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
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";
1365 doc.
add_posting(
"knife", n *
unsigned(log(
double(n + 2))));
1466 for (
int i = 0; i < 5; ++i) {
1475 for (
int i = 0; i < 5; ++i) {
1526 Xapian::docid max_id = numeric_limits<Xapian::docid>::max();
1572 e =
"|asd|asd1|asd10|asd2|asd3|asd4|asd5|asd6|";
1596 for (
int times = 1; times <= 2; ++times) {
1634 for (
int times = 1; times <= 2; ++times) {
1697 for (
size_t i = 246; i <= 290; ++i) {
1699 tout <<
"Term length " << i <<
'\n';
1701 string term(i,
'X');
1711 TEST(e.
get_msg().find(
"Term too long (> 245)") != string::npos);
1715 for (
size_t j = 240; j <= 245; ++j) {
1717 tout <<
"Term length " << j <<
'\n';
1719 string term(j,
'X');
1731 doc.
add_term(
string(limit / 2 + 1,
'\0'));
1741 string target =
" is ";
1742 target +=
str(limit);
1810 string synonym(255,
'x');
1811 char buf[] =
" iamafish!!!!!!!!!!";
1812 for (
int i = 33; i < 120; ++i) {
1827 static const int terms[] = { 219, 221, 222, 223, 224, 225, 226 };
1828 static const int copies[] = { 74, 116, 199, 21, 45, 155, 189 };
1833 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1840 for (
size_t c = copies[i]; c; --c)
1846 for (
size_t i = 0; i <
sizeof(terms) /
sizeof(terms[0]); ++i) {
1863 if (vals.empty())
return;
1865 map<Xapian::docid, string>::const_iterator i;
1866 for (i = vals.begin(); i != vals.end(); ++i) {
1868 tout <<
"Checking value in doc " << i->first <<
" - should be '" << i->second <<
"'\n";
1872 if (dbval.empty()) {
1891 unsigned int seed = 7;
1895 static_assert(
doccount % 13 != 0,
"doccount divisible by 13");
1897 map<Xapian::docid, string> vals;
1902 string val =
"val" +
str(num);
1903 tout <<
"Setting val '" << val <<
"' in doc " << num <<
"\n";
1916 string val =
"newval0";
1917 tout <<
"Setting val '" << val <<
"' in doc 2\n";
1928 tout <<
"Replacing document 1 with itself\n";
1941 tout <<
"Replacing document 1 with itself, after reading doc 2.\n";
1952 tout <<
"Setting seed to " <<
seed <<
"\n";
1961 val =
"newval" +
str(num);
1962 tout <<
"Setting val '" << val <<
"' in doc " << did <<
"\n";
1965 tout <<
"Adding/replacing empty document " << did <<
"\n";
1979 tout <<
"Clearing val in doc " << did <<
"\n";
1982 vals[did] = string();
2020 string src_db_path =
2025 for (
int n =
'1'; n <=
'2'; ++n) {
2026 src_db_path.back() = n;
2028 cp_R(src_db_path, db_path);
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 gen_synonym_merge1b_db(Xapian::WritableDatabase &db, const string &)
static void gen_synonym_merge1a_db(Xapian::WritableDatabase &db, const 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)
DatabaseCorruptError indicates database corruption was detected.
DatabaseError indicates some sort of database related error.
DatabaseLockError indicates failure to lock a database.
An indexed database of documents.
Xapian::doccount get_termfreq(std::string_view term) const
Get the number of documents indexed by a specified term.
Xapian::TermIterator synonym_keys_begin(std::string_view prefix={}) const
An iterator which returns all terms which have synonyms.
static size_t check(std::string_view path, int opts=0, std::ostream *out=NULL)
Check the integrity of a database or database table.
PositionIterator positionlist_end(Xapian::docid, std::string_view) const noexcept
End iterator corresponding to positionlist_begin().
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
TermIterator termlist_begin(Xapian::docid did) const
Start iterating the terms in a document.
double get_avlength() const
Old name for get_average_length() for backward compatibility.
PositionIterator positionlist_begin(Xapian::docid did, std::string_view term) const
Start iterating positions for a term in a document.
size_t size() const
Return number of shards in this Database object.
Xapian::TermIterator synonyms_end(std::string_view) const noexcept
End iterator corresponding to synonyms_begin(term).
void add_database(const Database &other)
Add shards from another Database.
Xapian::TermIterator synonym_keys_end(std::string_view={}) const noexcept
End iterator corresponding to synonym_keys_begin(prefix).
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a specified document.
bool term_exists(std::string_view term) const
Test is a particular term is present in any document.
TermIterator allterms_end(std::string_view={}) const noexcept
End iterator corresponding to allterms_begin(prefix).
bool has_positions() const
Does this database have any positional information?
Xapian::termcount get_collection_freq(std::string_view term) const
Get the total number of occurrences of a specified term.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
PostingIterator postlist_end(std::string_view) const noexcept
End iterator corresponding to postlist_begin().
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
TermIterator allterms_begin(std::string_view prefix={}) const
Start iterating all terms in the database with a given prefix.
Xapian::TermIterator synonyms_begin(std::string_view term) const
An iterator which returns all the synonyms for a given term.
bool reopen()
Reopen the database at the latest available revision.
Xapian::Document get_document(Xapian::docid did, unsigned flags=0) const
Get a document from the database.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in a specified document.
Indicates an attempt to access a document not present in the database.
Class representing a document.
void set_data(std::string_view data)
Set the document data.
std::string get_data() const
Get the document data.
void add_term(std::string_view term, Xapian::termcount wdf_inc=1)
Add a term to this document.
Xapian::valueno values_count() const
Count the value slots used in this document.
ValueIterator values_begin() const
Start iterating the values in this document.
std::string get_value(Xapian::valueno slot) const
Read a value slot in this document.
void remove_term(std::string_view term)
Remove a term from this document.
void remove_posting(std::string_view term, Xapian::termpos term_pos, Xapian::termcount wdf_dec=1)
Remove posting for a term.
TermIterator termlist_end() const noexcept
End iterator corresponding to termlist_begin().
TermIterator termlist_begin() const
Start iterating the terms in this document.
ValueIterator values_end() const noexcept
End iterator corresponding to values_begin().
void add_value(Xapian::valueno slot, std::string_view value)
Add a value to a slot in this document.
void add_posting(std::string_view term, Xapian::termpos term_pos, Xapian::termcount wdf_inc=1)
Add a posting for a term.
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast=0, const RSet *rset=NULL, const MatchDecider *mdecider=NULL) const
Run the query.
void set_sort_by_value_then_relevance(valueno sort_key, bool reverse)
Set the sorting to be by value, then by relevance for documents with the same value.
void set_query(const Query &query, termcount query_length=0)
Set the query.
const std::string & get_msg() const noexcept
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.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Class representing a query.
Class for iterating over a list of terms.
PositionIterator positionlist_end() const noexcept
Return an end PositionIterator for the current term.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
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 clear_synonyms(std::string_view term) const
Remove all synonyms for a term.
void add_synonym(std::string_view term, std::string_view synonym) const
Add a synonym for a term.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a document in the database.
void commit()
Commit pending modifications.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
void remove_synonym(std::string_view term, std::string_view synonym) const
Remove a synonym for a term.
static std::string get_srcdir()
Read srcdir from environment and if not present, make a valiant attempt to guess a value.
Utility functions for testing files.
string str(int value)
Convert int to std::string.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
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.
Negate unsigned integer, avoiding compiler warnings.
constexpr std::enable_if_t< std::is_unsigned_v< T >, T > negate_unsigned(T value)
Various assertion macros.
<unistd.h>, but with compat.
Convert types to std::string.
Various handy string-related helpers.
#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.
#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.
void cp_R(const std::string &src, const std::string &dest)
Recursively copy a directory.
void rm_rf(const string &filename)
Remove a directory and contents, just like the Unix "rm -rf" command.
C++ function versions of useful Unix commands.
Public interfaces for the Xapian library.