69 "Query(<alldocuments>)");
75 vector<Xapian::Query> subqs;
117 # if __has_warning("-Wself-assign-overloaded")
120 # pragma clang diagnostic push
121 # pragma clang diagnostic ignored "-Wself-assign-overloaded"
126 # if __has_warning("-Wself-assign-overloaded")
127 # pragma clang diagnostic pop
156 # if __has_warning("-Wself-assign-overloaded")
159 # pragma clang diagnostic push
160 # pragma clang diagnostic ignored "-Wself-assign-overloaded"
165 # if __has_warning("-Wself-assign-overloaded")
166 # pragma clang diagnostic pop
195 # if __has_warning("-Wself-assign-overloaded")
198 # pragma clang diagnostic push
199 # pragma clang diagnostic ignored "-Wself-assign-overloaded"
204 # if __has_warning("-Wself-assign-overloaded")
205 # pragma clang diagnostic pop
238 q &= ~
Xapian::Query(
"bar");
240 q = ~
Xapian::Query(
"bar");
286 "Query(((a OR b) NEAR 2 (a OR b)))");
289 "Query(((a OR b) PHRASE 2 (a OR b)))");
342 static const char *
const subqs[] = {
343 "this",
"hack",
"which",
"paragraph",
"is",
"return",
"this",
"this"
397 "Query(\\xc0\\x80\\xf5\\x80\\x80\\x80\\xfe\\xff)");
399 "Query(\\x00\\x1f)");
402 "Query(back\\x5cslash)");
405 "Query(D\\x7f_\\x7f~)");
436 q = ~
Xapian::Query(
"bar");
475 static const char *
const phrase[] = {
"this",
"is",
"the" };
489 const char * terms[4];
492 #define WILDCARD_EXCEPTION { 0, 0, 0, "" }
497 {
"thou", 1,
'E', {
"though", 0, 0, 0 } },
498 {
"s", 2,
'F', {
"say",
"search", 0, 0 } },
499 {
"s", 2,
'M', {
"simpl",
"so", 0, 0 } }
514 tout << test.pattern <<
'\n';
515 auto tend = test.terms + 4;
516 while (tend[-1] == NULL) --tend;
517 bool expect_exception = (tend - test.terms == 4 && tend[-1][0] ==
'\0');
521 switch (test.max_type) {
534 q =
Xapian::Query(o, test.pattern, test.max_expansion, max_type);
541 TEST(!expect_exception);
548 TEST(expect_exception);
630 if (!terms.empty()) terms +=
' ';
656 #define QUERY_ALLDOCS "Query(<alldocuments>)"
684 doc.
add_term(
"t\xf3\x80\x80\x80st");
805 const char* terms[4];
808 #define EDITDIST_EXCEPTION { 0, 0, 0, "" }
813 {
"museum", 3, 3,
'E', {
"mset",
"must",
"use", 0 } },
814 {
"thou", 0, 9,
'E', { 0, 0, 0, 0 } },
815 {
"though", 0, 9,
'E', {
"though", 0, 0, 0 } },
816 {
"museum", 3, 1,
'F', {
"mset", 0, 0, 0 } },
817 {
"museum", 3, 1,
'M', {
"use", 0, 0, 0 } },
831 tout << test.target <<
'\n';
832 auto tend = test.terms + 4;
833 while (tend > test.terms && tend[-1] == NULL) --tend;
834 bool expect_exception = (tend - test.terms == 4 && tend[-1][0] ==
'\0');
837 switch (test.max_type) {
850 q =
Xapian::Query(o, test.target, test.max_expansion, max_type,
856 TEST(!expect_exception);
863 TEST(expect_exception);
869 #define UTF8(X) reinterpret_cast<const char*>(u8"" X "")
873 {
UTF8(
"\U00010000"), 1, 8,
'E', {
UTF8(
"a\U00010000"), 0, 0, 0 } },
890 tout << test.target <<
'\n';
891 auto tend = test.terms + 4;
892 while (tend > test.terms && tend[-1] == NULL) --tend;
893 bool expect_exception = (tend - test.terms == 4 && tend[-1][0] ==
'\0');
896 switch (test.max_type) {
909 q =
Xapian::Query(o, test.target, test.max_expansion, max_type,
915 TEST(!expect_exception);
922 TEST(expect_exception);
944 Xapian::Query q1(OP_EDIT_DISTANCE,
"Spossum", 0, 0, OP_SYNONYM, 2, 1);
963 const char * terms[4];
969 { 5, {
"expect",
"to",
"mset", 0 }, 0 },
970 { 5, {
"word",
"well",
"the", 0 }, 2 },
971 { 5, {
"if",
"word",
"doesnt", 0 }, 0 },
972 { 5, {
"at",
"line",
"three", 0 }, 0 },
973 { 5, {
"paragraph",
"other",
"the", 0 }, 0 },
974 { 5, {
"other",
"the",
"with", 0 }, 0 }
983 auto tend = test.terms + 4;
984 while (tend[-1] == NULL) --tend;
989 if (test.result == 0) {
1000 { 4, {
"test",
"the",
"with", 0 }, 1 },
1001 { 4, {
"expect",
"word",
"the", 0 }, 2 },
1002 { 4, {
"line",
"be",
"blank", 0 }, 1 },
1003 { 2, {
"banana",
"banana", 0, 0 }, 0 },
1004 { 3, {
"banana",
"banana", 0, 0 }, 0 },
1005 { 2, {
"word",
"word", 0, 0 }, 2 },
1006 { 4, {
"work",
"meant",
"work", 0 }, 0 },
1007 { 4, {
"this",
"one",
"yet",
"one" }, 0 }
1016 auto tend = test.terms + 4;
1017 while (tend[-1] == NULL) --tend;
1021 if (test.result == 0) {
1245 Query q = Query(
"the") &~ (Query(
"friedrich") &
1246 (Query(
"day") | Query(
"night")));
1258 Query q = Query(
"the") &~ Query(Query::OP_WILDCARD,
"pru");
1271 Query q(Query::OP_PHRASE, Query(
"the"), Query(
"king"));
1272 q &= ~Query(
"worldtornado");
1395 static const char*
const words[] = {
"hello",
"world"};
1473 q &= ~
Xapian::Query{
"XEP"};
1490 enq.set_query(
query);
1493 auto mset = enq.get_mset(0, 10,
nullptr, &mdecider);
1494 FAIL_TEST(
"Expected exception Exception_estimateop2 not thrown");
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
#define WILDCARD_EXCEPTION
DEFINE_TESTCASE(queryterms1, !backend)
static const editdist_testcase editdist1_testcases[]
static const editdist_testcase editdist2_testcases[]
static const positional_testcase loosephrase1_testcases[]
#define EDITDIST_EXCEPTION
static const wildcard_testcase wildcard1_testcases[]
static void gen_singlecharwildcard1_db(Xapian::WritableDatabase &db, const string &)
static void gen_multicharwildcard1_db(Xapian::WritableDatabase &db, const string &)
static const positional_testcase loosenear1_testcases[]
static void gen_subdbwithoutpos1_db(Xapian::WritableDatabase &db, const string &)
Xapian::Database get_database(const string &dbname)
test functionality of the Xapian API
#define SKIP_TEST_FOR_BACKEND(B)
bool operator()(const Xapian::Document &) const override
Decide whether to accept a document.
Class implementing a "boolean" weighting scheme.
An indexed database of documents.
void add_database(const Database &other)
Add shards from another Database.
bool has_positions() const
Does this database have any positional information?
Xapian::doccount get_doccount() const
Get the number of documents in the database.
Class representing a document.
void add_boolean_term(std::string_view term)
Add a boolean filter term to the document.
void add_term(std::string_view term, Xapian::termcount wdf_inc=1)
Add a term to this document.
void clear_terms()
Clear all terms from the document.
void add_posting(std::string_view term, Xapian::termpos term_pos, Xapian::termcount wdf_inc=1)
Add a posting for a term.
void set_weighting_scheme(const Weight &weight)
Set the weighting scheme to use.
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast=0, const RSet *rset=NULL, const MatchDecider *mdecider=NULL) const
Run the query.
TermIterator get_matching_terms_begin(docid did) const
Iterate query terms matching a document.
void set_query(const Query &query, termcount query_length=0)
Set the query.
TermIterator get_matching_terms_end(docid) const noexcept
End iterator corresponding to get_matching_terms_begin().
Class representing a list of search results.
Xapian::doccount size() const
Return number of items in this MSet object.
bool empty() const
Return true if this MSet object is empty.
double get_termweight(std::string_view term) const
Get the term weight of a term.
Xapian::doccount get_matches_upper_bound() const
Upper bound on the total number of matching documents.
Xapian::doccount get_matches_lower_bound() const
Lower bound on the total number of matching documents.
Xapian::doccount get_matches_estimated() const
Estimate of the total number of matching documents.
Abstract base class for match deciders.
Build a Xapian::Query object from a user query string.
Query parse_query(std::string_view query_string, unsigned flags=FLAG_DEFAULT, std::string_view default_prefix={})
Parse a query.
Class representing a query.
const Query get_subquery(size_t n) const
Read a top level subquery.
const TermIterator get_terms_begin() const
Begin iterator for terms in the query object.
const TermIterator get_unique_terms_begin() const
Begin iterator for unique terms in the query object.
Xapian::termcount get_leaf_wqf() const
Get the wqf parameter of a leaf node.
std::string get_description() const
Return a string describing this object.
op get_type() const noexcept
Get the type of the top level of the query.
const TermIterator get_unique_terms_end() const noexcept
End iterator for unique terms in the query object.
const TermIterator get_terms_end() const noexcept
End iterator for terms in the query object.
size_t get_num_subqueries() const noexcept
Get the number of subqueries of the top level query.
@ OP_SCALE_WEIGHT
Scale the weight contributed by a subquery.
@ OP_WILDCARD
Wildcard expansion.
@ OP_XOR
Match documents which an odd number of subqueries match.
@ OP_AND_MAYBE
Match the first subquery taking extra weight from other subqueries.
@ LEAF_MATCH_ALL
Value returned by get_type() for MatchAll or equivalent.
@ OP_NEAR
Match only documents where all subqueries match near each other.
@ OP_AND
Match only documents which all subqueries match.
@ LEAF_MATCH_NOTHING
Value returned by get_type() for MatchNothing or equivalent.
@ OP_OR
Match documents which at least one subquery matches.
@ OP_FILTER
Match like OP_AND but only taking weight from the first subquery.
@ OP_PHRASE
Match only documents where all subqueries match near and in order.
@ OP_SYNONYM
Match like OP_OR but weighting as if a single term.
@ OP_AND_NOT
Match documents which the first subquery matches but no others do.
@ OP_EDIT_DISTANCE
Edit distance expansion.
@ LEAF_TERM
Value returned by get_type() for a term.
@ OP_VALUE_GE
Match only documents where a value slot is >= a given value.
Xapian::termpos get_leaf_pos() const
Get the pos parameter of a leaf node.
static const Xapian::Query MatchNothing
A query matching no documents.
@ WILDCARD_PATTERN_MULTI
Support * which matches 0 or more characters.
@ WILDCARD_LIMIT_ERROR
Throw an error if OP_WILDCARD exceeds its expansion limit.
@ WILDCARD_PATTERN_GLOB
Enable all supported glob-like features.
@ WILDCARD_LIMIT_FIRST
Stop expanding when OP_WILDCARD reaches its expansion limit.
@ WILDCARD_LIMIT_MOST_FREQUENT
Limit OP_WILDCARD expansion to the most frequent terms.
@ WILDCARD_PATTERN_SINGLE
Support ? which matches a single character.
static const Xapian::Query MatchAll
A query matching all documents.
UnimplementedError indicates an attempt to use an unimplemented feature.
A posting source which reads weights from a value slot.
WildcardError indicates an error expanding a wildcarded query.
This class provides read/write access to a database.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
The Xapian namespace contains public interfaces for the Xapian library.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Xapian::termcount max_expansion
Xapian::termcount max_expansion
#define TEST_REL(A, REL, B)
Test a relation holds,e.g. TEST_REL(a,>,b);.
std::ostringstream tout
The debug printing stream.
a generic test suite engine
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
#define TEST_EQUAL(a, b)
Test for equality of two things.
#define TEST_STRINGS_EQUAL(a, b)
Test for equality of two strings.
#define TEST_EQUAL_DOUBLE(a, b)
Test two doubles for near equality.
#define TEST(a)
Test a condition, without an additional explanation for failure.
void mset_expect_order(const Xapian::MSet &A, Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4, Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8, Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
bool mset_range_is_same(const Xapian::MSet &mset1, unsigned int first1, const Xapian::MSet &mset2, unsigned int first2, unsigned int count)
Xapian-specific test helper functions and macros.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
Public interfaces for the Xapian library.