104 bool sharded = (db.
size() > 1);
116 doc1.
add_posting(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 1);
152 TEST_EQUAL(*iter1,
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
184 doc2.
remove_term(
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
299 term += char(t ^ 70 ^ i);
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") {
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
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());
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();
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())
static void test_emptyterm2_helper(Xapian::WritableDatabase &db)
static void gen_consistency2_db(Xapian::WritableDatabase &db, const string &)
static void gen_lazytablebug1_db(Xapian::WritableDatabase &db, const string &)
DEFINE_TESTCASE(adddoc1, writable)
static void gen_longpositionlist1_db(Xapian::WritableDatabase &db, const string &)
static void check_vals(const Xapian::Database &db, const map< Xapian::docid, string > &vals)
Helper function for modifyvalues1.
Xapian::Database get_writable_database_as_database()
Xapian::WritableDatabase get_writable_database(const string &dbname)
std::string get_named_writable_database_path(const std::string &name)
Xapian::WritableDatabase get_writable_database_again()
Xapian::Database get_database(const string &dbname)
Xapian::WritableDatabase get_named_writable_database(const std::string &name, const std::string &source)
test functionality of the Xapian API
#define SKIP_TEST_FOR_BACKEND(B)
DatabaseError indicates some sort of database related error.
DatabaseLockError indicates failure to lock a database.
This class is used to access a database, or a group of databases.
PostingIterator postlist_begin(const std::string &tname) const
An iterator pointing to the start of the postlist for a given term.
Xapian::TermIterator synonyms_end(const std::string &) const
Corresponding end iterator to synonyms_begin(term).
Xapian::TermIterator synonym_keys_begin(const std::string &prefix=std::string()) const
An iterator which returns all terms which have synonyms.
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
Xapian::doclength get_avlength() const
Get the average length of the documents in the database.
PostingIterator postlist_end(const std::string &) const
Corresponding end iterator to postlist_begin().
TermIterator termlist_begin(Xapian::docid did) const
An iterator pointing to the start of the termlist for a given document.
Xapian::termcount get_collection_freq(const std::string &tname) const
Return the total number of occurrences of the given term.
size_t size() const
Return number of shards in this Database object.
Xapian::TermIterator synonym_keys_end(const std::string &=std::string()) const
Corresponding end iterator to synonym_keys_begin(prefix).
Xapian::doccount get_termfreq(const std::string &tname) const
Get the number of documents in the database indexed by a given term.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a document.
Xapian::TermIterator synonyms_begin(const std::string &term) const
An iterator which returns all the synonyms for a given term.
TermIterator allterms_begin(const std::string &prefix=std::string()) const
An iterator which runs across all terms with a given prefix.
bool term_exists(const std::string &tname) const
Check if a given term exists in the database.
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 allterms_end(const std::string &=std::string()) const
Corresponding end iterator to allterms_begin(prefix).
bool has_positions() const
Does this database have any positional information?
Xapian::doccount get_doccount() const
Get the number of documents in the database.
Xapian::Document get_document(Xapian::docid did) const
Get a document from the database, given its document id.
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
bool reopen()
Re-open the database.
PositionIterator positionlist_end(Xapian::docid, const std::string &) const
Corresponding end iterator to positionlist_begin().
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.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
Indicates an attempt to access a document not present in the database.
A handle representing a document in a Xapian database.
void remove_term(const std::string &tname)
Remove a term and all postings associated with it.
void remove_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfdec=1)
Remove a posting of a term from the document.
void add_value(Xapian::valueno slot, const std::string &value)
Add a new value.
void add_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfinc=1)
Add an occurrence of a term at a particular position.
std::string get_data() const
Get data stored in the document.
ValueIterator values_begin() const
Iterator for the values in this document.
std::string get_value(Xapian::valueno slot) const
Get value by number.
TermIterator termlist_end() const
Equivalent end iterator for termlist_begin().
ValueIterator values_end() const
Equivalent end iterator for values_begin().
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.
TermIterator termlist_begin() const
Start iterating the terms in this document.
void set_data(const std::string &data)
Set data stored in the document.
Xapian::termcount values_count() const
Count the values in this document.
This class provides an interface to the information retrieval system for the purpose of searching.
void set_query(const Xapian::Query &query, Xapian::termcount qlen=0)
Set the query to run.
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.
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.
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
InvalidOperationError indicates the API was used in an invalid way.
Class representing a list of search results.
Xapian::doccount size() const
Return number of items in this MSet object.
Class for iterating over term positions.
Class for iterating over a list of terms.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Xapian::termcount get_doclength() const
Return the length of the document at the current position.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Class representing a query.
@ OP_NEAR
Match only documents where all subqueries match near each other.
@ OP_PHRASE
Match only documents where all subqueries match near and in order.
Class for iterating over a list of terms.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
Class for iterating over document values.
Xapian::valueno get_valueno() const
Return the value slot number for the current position.
This class provides read/write access to a database.
void delete_document(Xapian::docid did)
Delete a document from the database.
void remove_synonym(const std::string &term, const std::string &synonym) const
Remove a synonym for a term.
void clear_synonyms(const std::string &term) const
Remove all synonyms for a term.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
void commit()
Commit any pending modifications made to the database.
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
void add_synonym(const std::string &term, const std::string &synonym) const
Add a synonym for a term.
Utility functions for testing files.
bool file_exists(const char *path)
Test if a file exists.
string str(int value)
Convert int to std::string.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DB_OPEN
Open an existing database.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various assertion macros.
<unistd.h>, but with compat.
Convert types to std::string.
Various handy helpers which std::string really should provide.
bool endswith(const std::string &s, char sfx)
#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(a)
Test a condition, without an additional explanation for failure.
void XFAIL(const char *msg)
Mark a testcase as expected to fail.
#define TEST_NOT_EQUAL(a, b)
Test for non-equality of two things.
#define TEST_AND_EXPLAIN(a, b)
Test a condition, and display the test with an extra explanation if the condition fails.
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)
Xapian-specific test helper functions and macros.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
C++ function versions of useful Unix commands.
Public interfaces for the Xapian library.