114 doc1.
add_posting(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 1);
146 TEST_EQUAL(*iter1,
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
174 doc2.
remove_term(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
201 iter1 = doc1.termlist_begin();
203 TEST(iter1 != doc1.termlist_end());
211 TEST(iter1.positionlist_begin() == iter1.positionlist_end());
216 TEST(iter1 != doc1.termlist_end());
226 pi1 = iter1.positionlist_begin();
230 TEST(pi1 == iter1.positionlist_end());
235 TEST(iter1 != doc1.termlist_end());
243 TEST(iter1.positionlist_begin() == iter1.positionlist_end());
248 TEST(iter1 != doc1.termlist_end());
263 TEST(pi1 == iter1.positionlist_end());
268 TEST(iter1 == doc1.termlist_end());
281 term += char(t ^ 70 ^ i);
315 TEST(doc.termlist_begin() == doc.termlist_end());
329 document_in.
set_data(
"Foobar rising");
337 document_in2.
set_data(
"Foobar falling");
401 for (; i != document_in.
values_end(); i++, j++) {
432 if (*i ==
"foobar") {
442 for (; k != i.positionlist_end(); k++, l++) {
461 document_in.
set_data(
"Foobar rising");
523 # if __has_warning("-Wself-assign-overloaded") 526 # pragma clang diagnostic push 527 # pragma clang diagnostic ignored "-Wself-assign-overloaded" 533 # if __has_warning("-Wself-assign-overloaded") 534 # pragma clang diagnostic pop 570 doc1.add_term(
"fwing");
742 bool is_power_of_two = ((i & (i - 1)) == 0);
743 if (is_power_of_two) {
1202 for (
int n = 1; n <= 20; ++n) {
1204 string uterm =
"U" +
str(n % 16);
1222 for (
int n = 1; n <= 20; ++n) {
1223 string uterm =
"U" +
str(n % 16);
1224 if (uterm ==
"U2") {
1238 string uterm =
"U571";
1340 for (
int n = 1; n <= 20; ++n) {
1353 static const char *
const q1[] = {
"all",
"1" };
1362 static const char *
const q2[] = {
"1",
"2" };
1379 for (n = 1; n <= 2000; ++n) {
1381 doc.
add_posting(
"knife", n *
unsigned(log(
double(n + 2))));
1407 for (n = 1; n <= 2000; ++n) {
1420 for (n = 1; n <= 2000; ++n) {
1432 for (n = 1; n <= 2000; ++n) {
1434 TEST_EQUAL(*p, n *
unsigned(log(
double(n + 2))));
1444 for (n = 1; n <= 2000; ++n) {
1457 for (n = 1; n <= 2000; ++n) {
1478 for (i = 0; i < 5; ++i) {
1487 for (i = 0; i < 5; ++i) {
1516 for (i = 0; i < 8; ++i) {
1529 const char * base_ext =
".baseB";
1573 unlink((path +
"/record" + base_ext).c_str());
1574 unlink((path +
"/termlist" + base_ext).c_str());
1590 db.add_document(doc);
1603 db.add_document(doc);
1648 for (
int times = 1; times <= 2; ++times) {
1686 for (
int times = 1; times <= 2; ++times) {
1749 for (
size_t i = 246; i <= 290; ++i) {
1751 tout <<
"Term length " << i << endl;
1753 string term(i,
'X');
1763 TEST(e.
get_msg().find(
"Term too long (> 245)") != string::npos);
1767 for (
size_t j = 240; j <= 245; ++j) {
1769 tout <<
"Term length " << j << endl;
1771 string term(j,
'X');
1784 doc.
add_term(
string(limit / 2 + 1,
'\0'));
1794 string target =
" is ";
1795 target +=
str(limit);
1801 if (
get_dbtype().find(
"chert") != string::npos) {
1802 XFAIL(
"Chert fails to clear pending changes after " 1803 "InvalidArgumentError - fix too invasive");
1868 string synonym(255,
'x');
1869 char buf[] =
" iamafish!!!!!!!!!!";
1870 for (
int i = 33; i < 120; ++i) {
1890 static const int terms[] = { 219, 221, 222, 223, 224, 225, 226 };
1891 static const int copies[] = { 74, 116, 199, 21, 45, 155, 189 };
1896 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1903 size_t c = copies[i];
1909 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1926 if (vals.empty())
return;
1928 map<Xapian::docid, string>::const_iterator i;
1929 for (i = vals.begin(); i != vals.end(); ++i) {
1931 tout <<
"Checking value in doc " << i->first <<
" - should be '" << i->second <<
"'\n";
1935 if (dbval.empty()) {
1954 unsigned int seed = 7;
1958 static_assert(doccount % 13 != 0,
"doccount divisible by 13");
1960 map<Xapian::docid, string> vals;
1965 string val =
"val" +
str(num);
1966 tout <<
"Setting val '" << val <<
"' in doc " << num <<
"\n";
1979 string val =
"newval0";
1980 tout <<
"Setting val '" << val <<
"' in doc 2\n";
1991 tout <<
"Replacing document 1 with itself\n";
2004 tout <<
"Replacing document 1 with itself, after reading doc 2.\n";
2015 tout <<
"Setting seed to " << seed <<
"\n";
2024 val =
"newval" +
str(num);
2025 tout <<
"Setting val '" << val <<
"' in doc " << did <<
"\n";
2028 tout <<
"Adding/replacing empty document " << did <<
"\n";
2042 tout <<
"Clearing val in doc " << did <<
"\n";
2045 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.
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.
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)
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.
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.
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
Iterator for 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.