104 bool sharded = (db.
size() > 1);
116 doc1.
add_posting(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 1);
152 TEST_EQUAL(*iter1,
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
184 doc2.
remove_term(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
211 iter1 = doc1.termlist_begin();
213 TEST(iter1 != doc1.termlist_end());
223 TEST(iter1.positionlist_begin() == iter1.positionlist_end());
228 TEST(iter1 != doc1.termlist_end());
240 pi1 = iter1.positionlist_begin();
244 TEST(pi1 == iter1.positionlist_end());
249 TEST(iter1 != doc1.termlist_end());
259 TEST(iter1.positionlist_begin() == iter1.positionlist_end());
264 TEST(iter1 != doc1.termlist_end());
281 TEST(pi1 == iter1.positionlist_end());
286 TEST(iter1 == doc1.termlist_end());
299 term += char(t ^ 70 ^ i);
333 TEST(doc.termlist_begin() == doc.termlist_end());
347 document_in.
set_data(
"Foobar rising");
355 document_in2.
set_data(
"Foobar falling");
416 bool sharded = (database.
size() > 1);
423 for (; i != document_in.
values_end(); i++, j++) {
455 if (*i ==
"foobar") {
466 for (; k != i.positionlist_end(); k++, l++) {
485 document_in.
set_data(
"Foobar rising");
547 # if __has_warning("-Wself-assign-overloaded") 550 # pragma clang diagnostic push 551 # pragma clang diagnostic ignored "-Wself-assign-overloaded" 557 # if __has_warning("-Wself-assign-overloaded") 558 # pragma clang diagnostic pop 594 doc1.add_term(
"fwing");
766 bool is_power_of_two = ((i & (i - 1)) == 0);
767 if (is_power_of_two) {
1226 for (
int n = 1; n <= 20; ++n) {
1228 string uterm =
"U" +
str(n % 16);
1246 for (
int n = 1; n <= 20; ++n) {
1247 string uterm =
"U" +
str(n % 16);
1248 if (uterm ==
"U2") {
1262 string uterm =
"U571";
1366 for (
int n = 1; n <= 20; ++n) {
1379 static const char *
const q1[] = {
"all",
"1" };
1381 mymset = enquire.get_mset(0, 10);
1385 mymset = enquire.get_mset(0, 10);
1388 static const char *
const q2[] = {
"1",
"2" };
1390 mymset = enquire.get_mset(0, 10);
1394 mymset = enquire.get_mset(0, 10);
1404 doc.
add_posting(
"knife", n *
unsigned(log(
double(n + 2))));
1463 TEST_EQUAL(*p, n *
unsigned(log(
double(n + 2))));
1505 for (
int i = 0; i < 5; ++i) {
1514 for (
int i = 0; i < 5; ++i) {
1560 const char * base_ext =
".baseB";
1604 unlink((path +
"/record" + base_ext).c_str());
1605 unlink((path +
"/termlist" + base_ext).c_str());
1621 db.add_document(doc);
1634 db.add_document(doc);
1653 Xapian::docid max_id = numeric_limits<Xapian::docid>::max();
1683 for (
int times = 1; times <= 2; ++times) {
1721 for (
int times = 1; times <= 2; ++times) {
1784 for (
size_t i = 246; i <= 290; ++i) {
1786 tout <<
"Term length " << i <<
'\n';
1788 string term(i,
'X');
1798 TEST(e.
get_msg().find(
"Term too long (> 245)") != string::npos);
1802 for (
size_t j = 240; j <= 245; ++j) {
1804 tout <<
"Term length " << j <<
'\n';
1806 string term(j,
'X');
1819 doc.
add_term(
string(limit / 2 + 1,
'\0'));
1829 string target =
" is ";
1830 target +=
str(limit);
1836 if (
get_dbtype().find(
"chert") != string::npos) {
1837 XFAIL(
"Chert fails to clear pending changes after " 1838 "InvalidArgumentError - fix too invasive");
1902 string synonym(255,
'x');
1903 char buf[] =
" iamafish!!!!!!!!!!";
1904 for (
int i = 33; i < 120; ++i) {
1923 static const int terms[] = { 219, 221, 222, 223, 224, 225, 226 };
1924 static const int copies[] = { 74, 116, 199, 21, 45, 155, 189 };
1929 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1936 size_t c = copies[i];
1942 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1959 if (vals.empty())
return;
1961 map<Xapian::docid, string>::const_iterator i;
1962 for (i = vals.begin(); i != vals.end(); ++i) {
1964 tout <<
"Checking value in doc " << i->first <<
" - should be '" << i->second <<
"'\n";
1968 if (dbval.empty()) {
1987 unsigned int seed = 7;
1991 static_assert(doccount % 13 != 0,
"doccount divisible by 13");
1993 map<Xapian::docid, string> vals;
1998 string val =
"val" +
str(num);
1999 tout <<
"Setting val '" << val <<
"' in doc " << num <<
"\n";
2012 string val =
"newval0";
2013 tout <<
"Setting val '" << val <<
"' in doc 2\n";
2024 tout <<
"Replacing document 1 with itself\n";
2037 tout <<
"Replacing document 1 with itself, after reading doc 2.\n";
2048 tout <<
"Setting seed to " << seed <<
"\n";
2057 val =
"newval" +
str(num);
2058 tout <<
"Setting val '" << val <<
"' in doc " << did <<
"\n";
2061 tout <<
"Adding/replacing empty document " << did <<
"\n";
2075 tout <<
"Clearing val in doc " << did <<
"\n";
2078 vals[did] = string();
Xapian::doccount size() const
Return number of items in this MSet object.
Xapian::Document get_document(Xapian::docid did) const
Get a document from the database, given its document id.
bool endswith(const std::string &s, char sfx)
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
static void gen_consistency2_db(Xapian::WritableDatabase &db, const string &)
PositionIterator positionlist_end(Xapian::docid, const std::string &) const
Corresponding end iterator to positionlist_begin().
DEFINE_TESTCASE(adddoc1, writable)
void add_value(Xapian::valueno slot, const std::string &value)
Add a new value.
void set_sort_by_value_then_relevance(Xapian::valueno sort_key, bool reverse)
Set the sorting to be by value, then by relevance for documents with the same value.
static size_t check(const std::string &path, int opts=0, std::ostream *out=NULL)
Check the integrity of a database or database table.
TermIterator termlist_begin(Xapian::docid did) const
An iterator pointing to the start of the termlist for a given document.
#define TEST(a)
Test a condition, without an additional explanation for failure.
This class is used to access a database, or a group of databases.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
InvalidOperationError indicates the API was used in an invalid way.
PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const
An iterator pointing to the start of the position list for a given term in a given document...
#define TEST_AND_EXPLAIN(a, b)
Test a condition, and display the test with an extra explanation if the condition fails...
bool has_positions() const
Does this database have any positional information?
ValueIterator values_begin() const
Iterator for the values in this document.
TermIterator allterms_end(const std::string &=std::string()) const
Corresponding end iterator to allterms_begin(prefix).
Xapian::WritableDatabase get_writable_database(const string &dbname)
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
a generic test suite engine
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
bool reopen()
Re-open the database.
C++ function versions of useful Unix commands.
Class for iterating over document values.
void remove_term(const std::string &tname)
Remove a term and all postings associated with it.
Class representing a list of search results.
Xapian::WritableDatabase get_writable_database_again()
Xapian::TermIterator synonyms_end(const std::string &) const
Corresponding end iterator to synonyms_begin(term).
MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount checkatleast=0, const RSet *omrset=0, const MatchDecider *mdecider=0) const
Get (a portion of) the match set for the current query.
Convert types to std::string.
Utility functions for testing files.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
TermIterator termlist_end() const
Equivalent end iterator for termlist_begin().
Xapian::doccount get_doccount() const
Get the number of documents in the database.
static void gen_longpositionlist1_db(Xapian::WritableDatabase &db, const string &)
Xapian::WritableDatabase get_named_writable_database(const std::string &name, const std::string &source)
test functionality of the Xapian API
static void test_emptyterm2_helper(Xapian::WritableDatabase &db)
Xapian::doclength get_avlength() const
Get the average length of the documents in the database.
Class for iterating over a list of terms.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
#define TEST_REL(A, REL, B)
Test a relation holds,e.g. TEST_REL(a,>,b);.
Class for iterating over a list of terms.
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
#define TEST_NOT_EQUAL(a, b)
Test for non-equality of two things.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
void remove_synonym(const std::string &term, const std::string &synonym) const
Remove a synonym for a term.
std::string get_named_writable_database_path(const std::string &name)
DatabaseLockError indicates failure to lock a database.
const int DB_OPEN
Open an existing database.
This class provides read/write access to a database.
std::ostringstream tout
The debug printing stream.
Match only documents where all subqueries match near and in order.
Public interfaces for the Xapian library.
static void gen_lazytablebug1_db(Xapian::WritableDatabase &db, const string &)
void XFAIL(const char *msg)
Mark a testcase as expected to fail.
Xapian::TermIterator synonym_keys_begin(const std::string &prefix=std::string()) const
An iterator which returns all terms which have synonyms.
void delete_document(Xapian::docid did)
Delete a document from the database.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
Xapian::TermIterator synonym_keys_end(const std::string &=std::string()) const
Corresponding end iterator to synonym_keys_begin(prefix).
string str(int value)
Convert int to std::string.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a document.
void commit()
Commit any pending modifications made to the database.
Xapian::termcount values_count() const
Count the values in this document.
Xapian::Database get_writable_database_as_database()
Class for iterating over term positions.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
ValueIterator values_end() const
Equivalent end iterator for values_begin().
TermIterator allterms_begin(const std::string &prefix=std::string()) const
An iterator which runs across all terms with a given prefix.
Xapian::TermIterator synonyms_begin(const std::string &term) const
An iterator which returns all the synonyms for a given term.
#define SKIP_TEST_FOR_BACKEND(B)
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
void set_query(const Xapian::Query &query, Xapian::termcount qlen=0)
Set the query to run.
Indicates an attempt to access a document not present in the database.
size_t size() const
Return number of shards in this Database object.
bool term_exists(const std::string &tname) const
Check if a given term exists in the database.
void clear_synonyms(const std::string &term) const
Remove all synonyms for a term.
static void check_vals(const Xapian::Database &db, const map< Xapian::docid, string > &vals)
Helper function for modifyvalues1.
void add_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfinc=1)
Add an occurrence of a term at a particular position.
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
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())
Xapian::Database get_database(const string &dbname)
This class provides an interface to the information retrieval system for the purpose of searching...
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Match only documents where all subqueries match near each other.
Xapian::termcount get_doclength() const
Return the length of the document at the current position.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Xapian-specific test helper functions and macros.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various handy helpers which std::string really should provide.
#define TEST_STRINGS_EQUAL(a, b)
Test for equality of two strings.
<unistd.h>, but with compat.
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)
Various assertion macros.
void add_synonym(const std::string &term, const std::string &synonym) const
Add a synonym for a term.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Class representing a query.
DatabaseError indicates some sort of database related error.
std::string get_data() const
Get data stored in the document.
#define TEST_EQUAL(a, b)
Test for equality of two things.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
PostingIterator postlist_end(const std::string &) const
Corresponding end iterator to postlist_begin().
void set_data(const std::string &data)
Set data stored in the document.
bool file_exists(const char *path)
Test if a file exists.
std::string get_value(Xapian::valueno slot) const
Get value by number.
TermIterator termlist_begin() const
Start iterating the terms in this document.
Xapian::doccount get_termfreq(const std::string &tname) const
Get the number of documents in the database indexed by a given term.
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
A handle representing a document in a Xapian database.
void remove_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfdec=1)
Remove a posting of a term from the document.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
PostingIterator postlist_begin(const std::string &tname) const
An iterator pointing to the start of the postlist for a given term.
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.
Xapian::termcount get_collection_freq(const std::string &tname) const
Return the total number of occurrences of the given term.