tests/queryparsertest.cc File Reference

#include <config.h>
#include <xapian.h>
#include "cputimer.h"
#include "str.h"
#include "stringutils.h"
#include "utils.h"
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include "testsuite.h"
#include "testutils.h"

Include dependency graph for queryparsertest.cc:

Go to the source code of this file.

Classes

struct  test
struct  AuthorValueRangeProcessor

Defines

#define TESTCASE(S)   {#S, test_##S}
#define END_OF_TESTCASES   {0, 0}

Functions

static bool test_queryparser1 ()
static bool test_qp_default_op1 ()
static bool test_qp_default_prefix1 ()
static bool test_qp_default_prefix2 ()
static bool test_qp_odd_chars1 ()
static bool test_qp_flag_wildcard1 ()
static bool test_qp_flag_wildcard2 ()
static void test_qp_flag_wildcard1_helper (const Xapian::Database &db, Xapian::termcount max_expansion, const string &query_string)
static bool test_qp_flag_wildcard3 ()
static bool test_qp_flag_partial1 ()
static bool test_qp_flag_bool_any_case1 ()
static bool test_qp_stopper1 ()
static bool test_qp_flag_pure_not1 ()
static bool test_qp_unstem_boolean_prefix ()
static bool test_qp_value_range1 ()
static bool test_qp_value_range2 ()
static bool test_qp_value_range3 ()
static bool test_qp_value_range4 ()
 Test a boolean filter which happens to contain "..".
static bool test_value_range_serialise1 ()
static bool test_qp_value_daterange1 ()
static bool test_qp_value_daterange2 ()
static bool test_qp_value_stringrange1 ()
static bool test_qp_value_customrange1 ()
static bool test_qp_stoplist1 ()
static bool test_qp_spell1 ()
static bool test_qp_spell2 ()
static bool test_qp_spellwild1 ()
static bool test_qp_spellpartial1 ()
static bool test_qp_synonym1 ()
static bool test_qp_synonym2 ()
static bool test_qp_synonym3 ()
static bool test_qp_stem_all1 ()
static double time_query_parse (const Xapian::Database &db, const string &q, int repetitions, unsigned flags)
static void qp_scale1_helper (const Xapian::Database &db, const string &q, unsigned n, unsigned flags)
static bool test_qp_scale1 ()
static bool test_qp_near1 ()
static bool test_qp_phrase1 ()
static bool test_qp_stopword_group1 ()
static bool test_qp_default_op2 ()
 Regression test for bug with default_op set such that we get an exception.
int main (int argc, char **argv)

Variables

static const test test_or_queries []
static const test test_and_queries []
static const test test_stop_queries []
static const test test_pure_not_queries []
static const test test_value_range1_queries []
static const test test_value_range2_queries []
static const double test_value_range_numbers []
static const test test_value_range4_queries []
static const test test_value_daterange1_queries []
static const test test_value_daterange2_queries []
static const test test_value_stringrange1_queries []
static const test test_value_customrange1_queries []
static const test test_mispelled_queries []
static const test test_mispelled_wildcard_queries []
static const test test_mispelled_partial_queries []
static const test test_synonym_queries []
static const test test_multi_synonym_queries []
static const test test_synonym_op_queries []
static const test test_stem_all_queries []
static const test test_near_queries []
static const test test_phrase_queries []
static const test test_stopword_group_or_queries []
static const test test_stopword_group_and_queries []
static const test_desc tests []
 Test cases for the QueryParser.


Define Documentation

#define END_OF_TESTCASES   {0, 0}

Definition at line 41 of file queryparsertest.cc.

#define TESTCASE (  )     {#S, test_##S}

Definition at line 40 of file queryparsertest.cc.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 2526 of file queryparsertest.cc.

References test_driver::parse_command_line(), and test_driver::run().

static void qp_scale1_helper ( const Xapian::Database db,
const string &  q,
unsigned  n,
unsigned  flags 
) [static]

Definition at line 2156 of file queryparsertest.cc.

References SKIP_TEST, TEST_REL, time_query_parse(), and tout.

Referenced by test_qp_scale1().

static bool test_qp_default_op1 (  )  [static]

static bool test_qp_default_op2 (  )  [static]

static bool test_qp_default_prefix1 (  )  [static]

static bool test_qp_default_prefix2 (  )  [static]

static bool test_qp_flag_bool_any_case1 (  )  [static]

static bool test_qp_flag_partial1 (  )  [static]

static bool test_qp_flag_pure_not1 (  )  [static]

static bool test_qp_flag_wildcard1 (  )  [static]

static void test_qp_flag_wildcard1_helper ( const Xapian::Database db,
Xapian::termcount  max_expansion,
const string &  query_string 
) [static]

static bool test_qp_flag_wildcard2 (  )  [static]

static bool test_qp_flag_wildcard3 (  )  [static]

static bool test_qp_near1 (  )  [static]

static bool test_qp_odd_chars1 (  )  [static]

static bool test_qp_phrase1 (  )  [static]

static bool test_qp_scale1 (  )  [static]

static bool test_qp_spell1 (  )  [static]

static bool test_qp_spell2 (  )  [static]

static bool test_qp_spellpartial1 (  )  [static]

static bool test_qp_spellwild1 (  )  [static]

static bool test_qp_stem_all1 (  )  [static]

static bool test_qp_stoplist1 (  )  [static]

static bool test_qp_stopper1 (  )  [static]

static bool test_qp_stopword_group1 (  )  [static]

static bool test_qp_synonym1 (  )  [static]

static bool test_qp_synonym2 (  )  [static]

static bool test_qp_synonym3 (  )  [static]

static bool test_qp_unstem_boolean_prefix (  )  [static]

static bool test_qp_value_customrange1 (  )  [static]

static bool test_qp_value_daterange1 (  )  [static]

static bool test_qp_value_daterange2 (  )  [static]

static bool test_qp_value_range1 (  )  [static]

static bool test_qp_value_range2 (  )  [static]

static bool test_qp_value_range3 (  )  [static]

static bool test_qp_value_range4 (  )  [static]

Test a boolean filter which happens to contain "..".

Regression test for bug fixed in 1.2.3.

Also test that the same prefix can be set for a valuerange and filter.

Definition at line 1509 of file queryparsertest.cc.

References Xapian::QueryParser::add_boolean_prefix(), Xapian::QueryParser::add_valuerangeprocessor(), Xapian::Error::get_description(), Xapian::Query::get_description(), Xapian::Error::get_msg(), Xapian::QueryParser::parse_query(), test::query, TEST_STRINGS_EQUAL, and tout.

static bool test_qp_value_stringrange1 (  )  [static]

static bool test_queryparser1 (  )  [static]

static bool test_value_range_serialise1 (  )  [static]

static double time_query_parse ( const Xapian::Database db,
const string &  q,
int  repetitions,
unsigned  flags 
) [static]


Variable Documentation

const test test_and_queries[] [static]

Initial value:

 {
    { "internet explorer title:(http www)", "(Zinternet:(pos=1) AND Zexplor:(pos=2) AND ZXThttp:(pos=3) AND ZXTwww:(pos=4))" },
    
    
    { "one +two three", "(Zone:(pos=1) AND Ztwo:(pos=2) AND Zthree:(pos=3))" },
    { "hello -title:\"hello world\"", "(Zhello:(pos=1) AND_NOT (XThello:(pos=2) PHRASE 2 XTworld:(pos=3)))" },
    
    
    { "\"hello world\" -C++", "((hello:(pos=1) PHRASE 2 world:(pos=2)) AND_NOT c++:(pos=3))" },
    
    
    { "-cup site:world", "(0 * Hworld AND_NOT Zcup:(pos=1))" },
    { "site:world -cup", "(0 * Hworld AND_NOT Zcup:(pos=1))" },
    
    { "(site:world) -cup", "(0 * Hworld AND_NOT Zcup:(pos=1))" },
    
    
    
    { "foo site:xapian.org bar", "((Zfoo:(pos=1) AND Zbar:(pos=2)) FILTER Hxapian.org)" },
    
    { "a b site:xapian.org", "((Za:(pos=1) AND Zb:(pos=2)) FILTER Hxapian.org)" },
    { "site:xapian.org a b", "((Za:(pos=1) AND Zb:(pos=2)) FILTER Hxapian.org)" },
    
    { "author:험가 OR subject:万众 hello world!", "((A험:(pos=1) AND A험가:(pos=1) AND A가:(pos=1)) OR (XT万:(pos=2) AND XT万众:(pos=2) AND XT众:(pos=2) AND Zhello:(pos=3) AND Zworld:(pos=4)))" },
    { "洛伊one儿差点two脸three", "(洛:(pos=1) AND 洛伊:(pos=1) AND 伊:(pos=1) AND Zone:(pos=2) AND 儿:(pos=3) AND 儿差:(pos=3) AND 差:(pos=3) AND 差点:(pos=3) AND 点:(pos=3) AND Ztwo:(pos=4) AND 脸:(pos=5) AND Zthree:(pos=6))" },
    { NULL, NULL }
}

Definition at line 703 of file queryparsertest.cc.

Initial value:

 {
    { "doucment", "" },
    { "doucment ", "document " },
    { "documen", "" },
    { "documen ", "document " },
    { "seearch documen", "search documen" },
    { "search documen", "" },
    { NULL, NULL }
}

Definition at line 1918 of file queryparsertest.cc.

const test test_mispelled_queries[] [static]

Initial value:

 {
    { "doucment search", "document search" },
    { "doucment seeacrh", "document search" },
    { "docment seeacrh test", "document search test" },
    { "\"paragahp pineapple\"", "\"paragraph pineapple\"" },
    { "\"paragahp pineapple\"", "\"paragraph pineapple\"" },
    { "test S.E.A.R.C.", "" },
    { "this AND that", "" },
    { "documento", "document" },
    { "documento-documento", "document-document" },
    { "documento-searcho", "document-search" },
    { "test saerch", "test search" },
    { "paragraf search", "paragraph search" },
    { NULL, NULL }
}

Definition at line 1781 of file queryparsertest.cc.

Initial value:

 {
    { "doucment", "document" },
    { "doucment*", "" },
    { "doucment* seearch", "doucment* search" },
    { "doucment* search", "" },
    { NULL, NULL }
}

Definition at line 1871 of file queryparsertest.cc.

const test test_multi_synonym_queries[] [static]

Initial value:

 {
    { "sun OR tan OR cream", "(Zsun:(pos=1) OR Ztan:(pos=2) OR Zcream:(pos=3))" },
    { "sun tan", "((Zsun:(pos=1) OR Ztan:(pos=2)) SYNONYM bathe:(pos=1))" },
    { "sun tan cream", "((Zsun:(pos=1) OR Ztan:(pos=2) OR Zcream:(pos=3)) SYNONYM lotion:(pos=1))" },
    { "beach sun tan holiday", "(Zbeach:(pos=1) OR ((Zsun:(pos=2) OR Ztan:(pos=3)) SYNONYM bathe:(pos=2)) OR Zholiday:(pos=4))" },
    { "sun tan sun tan cream", "(((Zsun:(pos=1) OR Ztan:(pos=2)) SYNONYM bathe:(pos=1)) OR ((Zsun:(pos=3) OR Ztan:(pos=4) OR Zcream:(pos=5)) SYNONYM lotion:(pos=3)))" },
    { "single", "(Zsingl:(pos=1) SYNONYM record:(pos=1))" },
    { NULL, NULL }
}

Definition at line 2005 of file queryparsertest.cc.

const test test_near_queries[] [static]

Definition at line 2231 of file queryparsertest.cc.

const test test_or_queries[] [static]

Definition at line 51 of file queryparsertest.cc.

const test test_phrase_queries[] [static]

Definition at line 2303 of file queryparsertest.cc.

const test test_pure_not_queries[] [static]

Initial value:

 {
    { "NOT windows", "(<alldocuments> AND_NOT Zwindow:(pos=1))" },
    { "a AND (NOT b)", "(Za:(pos=1) AND (<alldocuments> AND_NOT Zb:(pos=2)))" },
    { "AND NOT windows", "Syntax: <expression> AND NOT <expression>" },
    { "gordian NOT", "Syntax: <expression> NOT <expression>" },
    { "gordian AND NOT", "Syntax: <expression> AND NOT <expression>" },
    { NULL, NULL }
}

Definition at line 1217 of file queryparsertest.cc.

const test test_stem_all_queries[] [static]

Initial value:

 {
    { "\"chemical engineers\"", "(chemic:(pos=1) PHRASE 2 engin:(pos=2))" },
    { "chemical NEAR engineers", "(chemic:(pos=1) NEAR 11 engin:(pos=2))" },
    { "chemical engineers", "(chemic:(pos=1) OR engin:(pos=2))" },
    { NULL, NULL }
}

Definition at line 2102 of file queryparsertest.cc.

const test test_stop_queries[] [static]

Initial value:

 {
    { "test the queryparser", "(test:(pos=1) AND queryparser:(pos=3))" },
    
    
    { "test AND the AND queryparser", "(test:(pos=1) AND the:(pos=2) AND queryparser:(pos=3))" },
    
    
    { "the", "the:(pos=1)" },
    
    
    
    
    { "an the a", "(an:(pos=1) AND the:(pos=2) AND a:(pos=3))" },
    
    
    { "the AND a an", "(the:(pos=1) AND a:(pos=2) AND an:(pos=3))" },
    { NULL, NULL }
}

Definition at line 1168 of file queryparsertest.cc.

Initial value:

 {
    { "this is a test", "test:(pos=4)" },
    { "test*", "(test:(pos=1) SYNONYM testable:(pos=1) SYNONYM tester:(pos=1))" },
    { "a test*", "(test:(pos=2) SYNONYM testable:(pos=2) SYNONYM tester:(pos=2))" },
    
    { "is a test*", "(test:(pos=3) SYNONYM testable:(pos=3) SYNONYM tester:(pos=3))" },
    
    { "this is a test*", "(test:(pos=4) SYNONYM testable:(pos=4) SYNONYM tester:(pos=4))" },
    
    { "this is a us* test*", "(user:(pos=4) AND (test:(pos=5) SYNONYM testable:(pos=5) SYNONYM tester:(pos=5)))" },
    { "this is a user test*", "(user:(pos=4) AND (test:(pos=5) SYNONYM testable:(pos=5) SYNONYM tester:(pos=5)))" },
    { NULL, NULL }
}

Definition at line 2389 of file queryparsertest.cc.

Initial value:

 {
    { "this is a test", "test:(pos=4)" },
    { "test*", "(test:(pos=1) SYNONYM testable:(pos=1) SYNONYM tester:(pos=1))" },
    { "a test*", "(test:(pos=2) SYNONYM testable:(pos=2) SYNONYM tester:(pos=2))" },
    { "is a test*", "(test:(pos=3) SYNONYM testable:(pos=3) SYNONYM tester:(pos=3))" },
    { "this is a test*", "(test:(pos=4) SYNONYM testable:(pos=4) SYNONYM tester:(pos=4))" },
    { "this is a us* test*", "(user:(pos=4) OR (test:(pos=5) SYNONYM testable:(pos=5) SYNONYM tester:(pos=5)))" },
    { "this is a user test*", "(user:(pos=4) OR (test:(pos=5) SYNONYM testable:(pos=5) SYNONYM tester:(pos=5)))" },
    { NULL, NULL }
}

Definition at line 2378 of file queryparsertest.cc.

const test test_synonym_op_queries[] [static]

Initial value:

 {
    { "searching", "Zsearch:(pos=1)" },
    { "~searching", "(Zsearch:(pos=1) SYNONYM Zfind:(pos=1) SYNONYM Zlocate:(pos=1))" },
    { "~search", "(Zsearch:(pos=1) SYNONYM find:(pos=1))" },
    { "~Search", "(search:(pos=1) SYNONYM find:(pos=1))" },
    { "~Searching", "searching:(pos=1)" },
    { "~searching OR terms", "((Zsearch:(pos=1) SYNONYM Zfind:(pos=1) SYNONYM Zlocate:(pos=1)) OR Zterm:(pos=2))" },
    { "~search OR terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) OR Zterm:(pos=2))" },
    { "~search +terms", "(Zterm:(pos=2) AND_MAYBE (Zsearch:(pos=1) SYNONYM find:(pos=1)))" },
    { "~search -terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) AND_NOT Zterm:(pos=2))" },
    { "+~search terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) AND_MAYBE Zterm:(pos=2))" },
    { "-~search terms", "(Zterm:(pos=2) AND_NOT (Zsearch:(pos=1) SYNONYM find:(pos=1)))" },
    { "~search terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) OR Zterm:(pos=2))" },
    
    { "~\"search terms\"", "(search:(pos=1) PHRASE 2 terms:(pos=2))" },
    { NULL, NULL }
}

Definition at line 2048 of file queryparsertest.cc.

const test test_synonym_queries[] [static]

Initial value:

 {
    { "searching", "(Zsearch:(pos=1) SYNONYM Zfind:(pos=1) SYNONYM Zlocate:(pos=1))" },
    { "search", "(Zsearch:(pos=1) SYNONYM find:(pos=1))" },
    { "Search", "(search:(pos=1) SYNONYM find:(pos=1))" },
    { "Searching", "searching:(pos=1)" },
    { "searching OR terms", "((Zsearch:(pos=1) SYNONYM Zfind:(pos=1) SYNONYM Zlocate:(pos=1)) OR Zterm:(pos=2))" },
    { "search OR terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) OR Zterm:(pos=2))" },
    { "search +terms", "(Zterm:(pos=2) AND_MAYBE (Zsearch:(pos=1) SYNONYM find:(pos=1)))" },
    { "search -terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) AND_NOT Zterm:(pos=2))" },
    { "+search terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) AND_MAYBE Zterm:(pos=2))" },
    { "-search terms", "(Zterm:(pos=2) AND_NOT (Zsearch:(pos=1) SYNONYM find:(pos=1)))" },
    { "search terms", "((Zsearch:(pos=1) SYNONYM find:(pos=1)) OR Zterm:(pos=2))" },
    
    { "\"search terms\"", "(search:(pos=1) PHRASE 2 terms:(pos=2))" },
    { NULL, NULL }
}

Definition at line 1956 of file queryparsertest.cc.

Initial value:

 {
    { "mars author:Asimov..Bradbury", "(mars:(pos=1) FILTER VALUE_RANGE 4 asimov bradbury)" },
    { NULL, NULL }
}

Definition at line 1715 of file queryparsertest.cc.

Initial value:

 {
    { "12/03/99..12/04/01", "VALUE_RANGE 1 19991203 20011204" },
    { "03-12-99..04-14-01", "VALUE_RANGE 1 19990312 20010414" },
    { "01/30/60..02/02/59", "VALUE_RANGE 1 19600130 20590202" },
    { "1999-03-12..2001-04-14", "VALUE_RANGE 1 19990312 20010414" },
    { "12/03/99..02", "Unknown range operation" },
    { "1999-03-12..2001", "Unknown range operation" },
    { NULL, NULL }
}

Definition at line 1580 of file queryparsertest.cc.

Initial value:

 {
    { "created:12/03/99..12/04/01", "VALUE_RANGE 1 19991203 20011204" },
    { "modified:03-12-99..04-14-01", "VALUE_RANGE 2 19990312 20010414" },
    { "accessed:01/30/70..02/02/69", "VALUE_RANGE 3 19700130 20690202" },
    { "1999-03-12..2001-04-14", "Unknown range operation" },
    { "12/03/99..created:12/04/01", "Unknown range operation" },
    { "12/03/99created:..12/04/01", "Unknown range operation" },
    { "12/03/99..12/04/01created:", "Unknown range operation" },
    { "12/03/99..02", "Unknown range operation" },
    { "1999-03-12..2001", "Unknown range operation" },
    { NULL, NULL }
}

Definition at line 1619 of file queryparsertest.cc.

const test test_value_range1_queries[] [static]

Initial value:

 {
    { "a..b", "VALUE_RANGE 1 a b" },
    { "$50..100", "VALUE_RANGE 1 $50 100" },
    { "$50..$100", "VALUE_RANGE 1 $50 $100" },
    { "02/03/1979..10/12/1980", "VALUE_RANGE 1 02/03/1979 10/12/1980" },
    { "a..b hello", "(hello:(pos=1) FILTER VALUE_RANGE 1 a b)" },
    { "hello a..b", "(hello:(pos=1) FILTER VALUE_RANGE 1 a b)" },
    { "hello a..b world", "((hello:(pos=1) OR world:(pos=2)) FILTER VALUE_RANGE 1 a b)" },
    { "hello a..b test:foo", "(hello:(pos=1) FILTER (VALUE_RANGE 1 a b AND XTESTfoo))" },
    { "hello a..b test:foo test:bar", "(hello:(pos=1) FILTER (VALUE_RANGE 1 a b AND (XTESTfoo OR XTESTbar)))" },
    { "hello a..b c..d test:foo", "(hello:(pos=1) FILTER ((VALUE_RANGE 1 a b OR VALUE_RANGE 1 c d) AND XTESTfoo))" },
    { "hello a..b c..d test:foo test:bar", "(hello:(pos=1) FILTER ((VALUE_RANGE 1 a b OR VALUE_RANGE 1 c d) AND (XTESTfoo OR XTESTbar)))" },
    { "-5..7", "VALUE_RANGE 1 -5 7" },
    { "hello -5..7", "(hello:(pos=1) FILTER VALUE_RANGE 1 -5 7)" },
    { "-5..7 hello", "(hello:(pos=1) FILTER VALUE_RANGE 1 -5 7)" },
    { "\"time flies\" 09:00..12:30", "((time:(pos=1) PHRASE 2 flies:(pos=2)) FILTER VALUE_RANGE 1 09:00 12:30)" },
    
    { "..b", "VALUE_RANGE 1  b" },
    { "a..", "VALUE_GE 1 a" },
    { NULL, NULL }
}

Definition at line 1274 of file queryparsertest.cc.

const test test_value_range2_queries[] [static]

Definition at line 1326 of file queryparsertest.cc.

const test test_value_range4_queries[] [static]

Initial value:

 {
    { "id:19254@foo..example.com", "0 * Q19254@foo..example.com" },
    { "hello:world", "0 * XHELLOworld" },
    { "hello:mum..world", "VALUE_RANGE 1 mum world" },
    { NULL, NULL }
}

Definition at line 1496 of file queryparsertest.cc.

const double test_value_range_numbers[] [static]

Definition at line 1444 of file queryparsertest.cc.

Referenced by test_value_range_serialise1().

Initial value:

 {
    { "tag:bar..foo", "VALUE_RANGE 1 bar foo" },
    { "bar..foo", "VALUE_RANGE 0 bar foo" },
    { NULL, NULL }
}

Definition at line 1665 of file queryparsertest.cc.

const test_desc tests[] [static]

Test cases for the QueryParser.

Definition at line 2486 of file queryparsertest.cc.


Documentation for Xapian (version 1.2.8).
Generated on 14 Dec 2011 by Doxygen 1.5.9.