72 const char * dbpath =
".stub/stubdb1";
97 const char * dbpath =
".stub/stubdb2";
110 #ifdef XAPIAN_HAS_REMOTE_BACKEND
121 #ifdef XAPIAN_HAS_REMOTE_BACKEND
141 #ifdef XAPIAN_HAS_REMOTE_BACKEND
142 # define EXPECTED_EXCEPTION Xapian::DatabaseOpeningError
144 # define EXPECTED_EXCEPTION Xapian::FeatureUnavailableError
149 out <<
"remote foo\n";
162 #ifdef XAPIAN_HAS_REMOTE_BACKEND
165 out <<
"remote [::1]:65535\n";
207 out <<
"remote [::1]\n";
225 mkdir(
".stub", 0755);
226 const char * dbpath =
".stub/stubdb3";
227 ofstream out(dbpath);
242 mkdir(
".stub", 0755);
243 const char * dbpath =
".stub/stubdb4";
244 ofstream out(dbpath);
246 out <<
"bad line here\n";
259 mkdir(
".stub", 0755);
260 const char * dbpath =
".stub/stubdb5";
261 ofstream out(dbpath);
276 mkdir(
".stub", 0755);
277 const char * dbpath =
".stub/stubdb6";
278 ofstream out(dbpath);
322 mkdir(
".stub", 0755);
323 const char * dbpath =
".stub/stubdb8";
324 ofstream out(dbpath);
331 FAIL_TEST(
"Managed to check inmemory stub");
335 "InMemory database checking not implemented");
347 return doc.
get_data().find(needle) != string::npos;
374 for ( ; i != mymset.
end(); ++i) {
376 TEST(myfunctor(doc));
377 docid_checked[*i] =
true;
387 mymset = enquire.
get_mset(0, 0, 0, &myfunctor);
401 mymset = enquire.
get_mset(0, 1, 0, &myfunctor);
417 for (
Xapian::docid did = 1; did < docid_checked.size(); ++did) {
418 if (!docid_checked[did]) {
426 mymset = enquire.
get_mset(0, 1, 0, &myfunctor);
445 mymset = enquire.
get_mset(0, 1, 0, &myfunctor);
462 mymset = enquire.
get_mset(0, 1, 0, &myfunctor);
495 for ( ; i != mymset.
end(); ++i) {
497 TEST(myfunctor(doc));
498 docid_checked[*i] =
true;
502 for (
Xapian::docid did = 1; did < docid_checked.size(); ++did) {
503 if (!docid_checked[did]) {
711 "Had no fewer items when performing collapse: don't know whether it worked.");
713 map<string, Xapian::docid> values;
715 for ( ; i != mymset.
end(); ++i) {
717 TEST(values[value] == 0 || value.empty());
761 "Lower bound was not lower when performing collapse: don't know whether it worked.");
763 "Upper bound was not lower when performing collapse: don't know whether it worked.");
765 map<string, Xapian::docid> values;
767 for ( ; i != mymset.
end(); ++i) {
769 TEST(values[value] == 0 || value.empty());
787 map<string, Xapian::docid> values;
789 for ( ; i != mymset.
end(); ++i) {
791 TEST(values[value] == 0 || value.empty());
810 "Lower bound was not 1 when performing collapse but not asking for any results.");
812 "Upper bound was changed when performing collapse but not asking for any results.");
814 map<string, Xapian::docid> values;
816 for ( ; i != mymset.
end(); ++i) {
818 TEST(values[value] == 0 || value.empty());
829 for (
int i = 0; i < 10; ++i) {
858 tout <<
"*ati = '" << *ati <<
"'\n";
859 tout <<
"*ati.length = '" << (*ati).length() <<
"'\n";
860 tout <<
"*ati == \"one\" = " << (*ati ==
"one") <<
"\n";
861 tout <<
"*ati[3] = " << ((*ati)[3]) <<
"\n";
862 tout <<
"*ati = '" << *ati <<
"'\n";
864 TEST(*ati ==
"three");
884 TEST(*ati ==
"five");
889 TEST(*ati ==
"four");
904 TEST(*ati ==
"three");
1008 for (m = mymset.
begin(); m != mymset.
end(); ++m) ++count;
1014 if (value_no == 0) {
1015 TEST(value.size() > 263);
1016 TEST_EQUAL(
static_cast<unsigned char>(value[262]), 255);
1017 for (
int k = 0; k < 256; ++k) {
1018 TEST_EQUAL(
static_cast<unsigned char>(value[k + 7]), k);
1027 for (m = mymset.
begin(); m != mymset.
end(); ++m) ++count;
1053 t.
skip_to(
string(
"big\0zero", 8));
1125 while (i != eset1.
end() && j != eset3.
end()) {
1134 bool eset1_eq_eset2 =
true;
1137 while (i != eset1.
end() && j != eset2.
end()) {
1139 eset1_eq_eset2 =
false;
1145 TEST(!eset1_eq_eset2);
1154 string s =
"let_us_see_if_we_can_break_it_with_a_really_really_long_term.";
1155 for (
int i = 0; i < 8; ++i) {
1171 TEST(
p.get_description() !=
"PostingIterator()");
1185 vector<Xapian::docid> v(
p, pend);
1189 vector<Xapian::docid>::const_iterator i;
1190 for (i = v.begin(); i != v.end(); ++i) {
1289 for (
int pass = 1; pass <= 2; ++pass) {
1291 tout <<
"Sorting on value " << value_no <<
'\n';
1301 j = allbset.
begin();
1302 for (i = partbset1.
begin(); i != partbset1.
end(); ++i) {
1303 tout <<
"Entry " << n <<
": " << *i <<
" | " << *j <<
'\n';
1305 if (*i != *j) ok =
false;
1310 for (i = partbset2.
begin(); i != partbset2.
end(); ++i) {
1311 tout <<
"Entry " << n <<
": " << *i <<
" | " << *j <<
'\n';
1313 if (*i != *j) ok =
false;
1319 FAIL_TEST(
"Split msets aren't consistent with unsplit");
1342 min(start + size, bigmset.
size()));
1350 bigmset[start + i].get_weight());
1374 mkdir(db_dir.c_str(), 0755);
1385 string empty_dir = db_dir +
"emptydirectory";
1386 mkdir(empty_dir.c_str(), 0700);
1390 string some_file = db_dir +
"somefile";
1423 string empty_dir =
"emptydirectory";
1424 mkdir(empty_dir.c_str(), 0700);
1431 #ifdef XAPIAN_HAS_GLASS_BACKEND
1432 const string dbdir =
".glass/test_glassdatabaseopen1";
1433 mkdir(
".glass", 0755);
1500 static const Xapian::docid order1[] = { 1,2,3,4,5,6,7,8,9 };
1501 static const Xapian::docid order2[] = { 2,1,3,6,5,4,7,9,8 };
1502 static const Xapian::docid order3[] = { 3,2,1,6,5,4,9,8,7 };
1503 static const Xapian::docid order4[] = { 7,8,9,4,5,6,1,2,3 };
1504 static const Xapian::docid order5[] = { 9,8,7,6,5,4,3,2,1 };
1505 static const Xapian::docid order6[] = { 7,9,8,6,5,4,2,1,3 };
1506 static const Xapian::docid order7[] = { 7,9,8,6,5,4,2,1,3 };
1507 static const Xapian::docid order8[] = { 2,6,7,1,5,9,3,4,8 };
1508 static const Xapian::docid order9[] = { 7,6,2,9,5,1,8,4,3 };
1515 for (i = 0; i <
sizeof(order1) /
sizeof(
Xapian::docid); ++i) {
1523 for (i = 0; i <
sizeof(order2) /
sizeof(
Xapian::docid); ++i) {
1531 for (i = 0; i <
sizeof(order1) /
sizeof(
Xapian::docid); ++i) {
1540 for (i = 0; i <
sizeof(order2) /
sizeof(
Xapian::docid); ++i) {
1549 for (i = 0; i <
sizeof(order3) /
sizeof(
Xapian::docid); ++i) {
1557 for (i = 0; i <
sizeof(order4) /
sizeof(
Xapian::docid); ++i) {
1565 for (i = 0; i <
sizeof(order5) /
sizeof(
Xapian::docid); ++i) {
1573 for (i = 0; i <
sizeof(order6) /
sizeof(
Xapian::docid); ++i) {
1581 for (i = 0; i <
sizeof(order7) /
sizeof(
Xapian::docid); ++i) {
1589 for (i = 0; i <
sizeof(order8) /
sizeof(
Xapian::docid); ++i) {
1597 for (i = 0; i <
sizeof(order8) /
sizeof(
Xapian::docid); ++i) {
1605 for (i = 0; i <
sizeof(order9) /
sizeof(
Xapian::docid); ++i) {
1613 for (i = 0; i <
sizeof(order9) /
sizeof(
Xapian::docid); ++i) {
1621 static const struct {
Xapian::docid did;
const char* text; } content[] = {
1622 {1,
"This is a test document used with the API test. This paragraph "
1623 "must be at least three lines (including the blank line) to be "
1624 "counted as a \"paragraph\"."},
1625 {2,
"This is a second simple data test, used to test multiple "
1626 "(inmemory anyway) databases. The text in this file is "
1627 "unimportant, although I suppose it ought to include the "
1628 "standard word \"word\" in a few places."},
1629 {3,
"This file will be indexed by paragraph, and the simple query will "
1630 "search for the word \"word\". Well expect the mset to contain "
1631 "two documents, including this paragraph and the fourth, below. "
1632 "Since this paragraph uses the word \"word\" so much, this "
1633 "should be the first one in the match set. Ill just say the word "
1634 "a few more times (word!) to make sure of that. If this doesnt "
1635 "word (typo, I meant work), then there may be fourletter words "
1637 {4,
"Ill leave this at two paragraphs. This one hasnt got any useful "
1638 "information in it either."},
1639 {5,
"This paragraph only has a load of absolute rubbish, and nothing "
1640 "of any use whatsoever."},
1641 {7,
"This is the other paragraph with the word in the simple query "
1642 "in it. For simplicity, all paragraphs are at least two lines, "
1643 "due to how the hacked up indexer works."},
1644 {9,
"This is another paragraph which wont be returned. Well, not "
1645 "with the simple query, anyway."},
1646 {11,
"And yet another. This one does mention banana splits, though, "
1647 "so cant be that bad."}
1654 for (
auto& i : content) {
1666 static const char *
const words[] = {
"paragraph",
"word" };
1668 const size_t MSET_SIZE = 10;
1686 static const pair<Xapian::docid, double> to_compare[] = {
1687 {7, 1.445962071042388164},
1688 {3, 1.4140112748017070743},
1689 {1, 1.3747698831232337824},
1690 {5, 1.1654938419498412916},
1691 {9, 1.1654938419498412916},
1692 {4, 1.1543806706320836053},
1693 {2, 0.12268031290495594321}
1708 void init(
double factor)
override {
1709 scale_factor = factor;
1713 std::string
name()
const override {
return "MyWeight"; }
1722 return scale_factor;
1733 static const char *
const query[] = {
1734 "this",
"line",
"paragraph",
"rubbish"
1790 mset_expect_order(mymset, 8, 6, 4, 5, 7, 10, 12, 11, 13, 9, 14);
1791 mymset = enq.
get_mset(0, 20, 0, NULL, &vsmd1);
1793 mymset = enq.
get_mset(0, 20, 0, NULL, &vsmd2);
static void make_netstats1_db(Xapian::WritableDatabase &db, const string &)
static Xapian::Query query(const string &t)
#define EXPECTED_EXCEPTION
DEFINE_TESTCASE(termstats, backend)
string get_database_path(const string &dbname)
Xapian::Database get_database(const string &dbname)
Xapian::Database get_remote_database(const string &dbname, unsigned int timeout, int *port_ptr)
test functionality of the Xapian API
Base class for backend handling in test harness.
static const char * get_xapian_progsrv_command()
Get the command line required to run xapian-progsrv.
GrepMatchDecider(const string &needle_)
bool operator()(const Xapian::Document &doc) const override
Decide whether to accept a document.
std::string name() const override
Return the name of this weighting scheme, e.g.
void init(double factor) override
Allow the subclass to perform any initialisation it needs to.
MyWeight * unserialise(const string &) const override
Unserialise parameters.
MyWeight * clone() const override
Clone this object.
string serialise() const override
Return this object's parameters serialised as a single string.
double get_sumpart(Xapian::termcount, Xapian::termcount, Xapian::termcount, Xapian::termcount) const override
Calculate the weight contribution for this object's term to a document.
double get_maxpart() const override
Return an upper bound on what get_sumpart() can return for any document.
DatabaseCreateError indicates a failure to create a database.
DatabaseLockError indicates failure to lock a database.
Indicates an attempt to access a database not present.
DatabaseOpeningError indicates failure to open 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.
static size_t check(std::string_view path, int opts=0, std::ostream *out=NULL)
Check the integrity of a database or database table.
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
void keep_alive()
Send a keep-alive message.
double get_avlength() const
Old name for get_average_length() for backward compatibility.
void add_database(const Database &other)
Add shards from another Database.
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).
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::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.
Class representing a document.
std::string get_data() const
Get the document data.
std::string get_value(Xapian::valueno slot) const
Read a value slot in this document.
Iterator over a Xapian::ESet.
double get_weight() const
Get the weight for the current position.
Class representing a list of search results.
Xapian::termcount size() const
Return number of items in this ESet object.
ESetIterator end() const
Return iterator pointing to just after the last item in this ESet.
ESetIterator begin() const
Return iterator pointing to the first item in this ESet.
void set_weighting_scheme(const Weight &weight)
Set the weighting scheme to use.
static const int USE_EXACT_TERMFREQ
Flag telling get_eset() to always use the exact term frequency.
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_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_cutoff(int percent_threshold, double weight_threshold=0)
Set lower bounds on percentage and/or weight.
void set_query(const Query &query, termcount query_length=0)
Set the query.
ESet get_eset(termcount maxitems, const RSet &rset, int flags=0, const ExpandDecider *edecider=NULL, double min_weight=0.0) const
Perform query expansion.
void set_sort_by_relevance_then_value(valueno sort_key, bool reverse)
Set the sorting to be by relevance then value.
void set_sort_by_value(valueno sort_key, bool reverse)
Set the sorting to be by value only.
void set_collapse_key(valueno collapse_key, doccount collapse_max=1)
Control collapsing of results.
void set_docid_order(docid_order order)
Set sort order for document IDs.
@ DESCENDING
docids sort in descending order.
@ ASCENDING
docids sort in ascending order (default)
TermIterator get_matching_terms_end(docid) const noexcept
End iterator corresponding to get_matching_terms_begin().
const std::string & get_msg() const noexcept
Message giving details of the error, intended for human consumption.
const std::string & get_context() const noexcept
Optional context information.
Indicates an attempt to use a feature which is unavailable.
Iterator over a Xapian::MSet.
Xapian::Document get_document() const
Get the Document object for the current position.
Class representing a list of search results.
Xapian::doccount size() const
Return number of items in this MSet object.
Xapian::doccount get_uncollapsed_matches_upper_bound() const
Upper bound on the total number of matching documents before collapsing.
Xapian::doccount get_uncollapsed_matches_estimated() const
Estimate of the total number of matching documents before collapsing.
Xapian::doccount get_uncollapsed_matches_lower_bound() const
Lower bound on the total number of matching documents before collapsing.
bool empty() const
Return true if this MSet object is empty.
Xapian::doccount get_matches_upper_bound() const
Upper bound on the total number of matching documents.
MSetIterator begin() const
Return iterator pointing to the first item in this MSet.
double get_max_attained() const
The maximum weight attained by any document.
Xapian::doccount get_matches_lower_bound() const
Lower bound on the total number of matching documents.
MSetIterator end() const
Return iterator pointing to just after the last item in this MSet.
Xapian::doccount get_matches_estimated() const
Estimate of the total number of matching documents.
Abstract base class for match deciders.
Indicates a problem communicating with a remote database.
Indicates a timeout expired while communicating with a remote database.
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.
std::string get_description() const
Return a string describing this object.
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_OR
Match documents which at least one subquery matches.
static const Xapian::Query MatchAll
A query matching all documents.
Class representing a set of documents judged as relevant.
void add_document(Xapian::docid did)
Mark a document as relevant.
Class representing a stemming algorithm.
Parses a piece of text and generate terms.
void index_text(const Xapian::Utf8Iterator &itor, Xapian::termcount wdf_inc=1, std::string_view prefix={})
Index some text.
void set_document(const Xapian::Document &doc)
Set the current document.
void set_stemming_strategy(stem_strategy strategy)
Set the stemming strategy.
void set_stemmer(const Xapian::Stem &stemmer)
Set the Xapian::Stem object to be used for generating stemmed terms.
Class for iterating over a list of terms.
void skip_to(std::string_view term)
Advance the iterator to term term.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
UnimplementedError indicates an attempt to use an unimplemented feature.
MatchDecider filtering results based on whether document values are in a user-defined set.
void add_value(const std::string &value)
Add a value to the test set.
Abstract base class for weighting schemes.
This class provides read/write access to a database.
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 sleep(double t)
Sleep until the time represented by this object.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
const int DB_CREATE
Create a new database.
const int DB_CREATE_OR_OPEN
Create database if it doesn't already exist.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DB_BACKEND_STUB
Open a stub database file.
const int DB_OPEN
Open an existing database.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
const int DB_BACKEND_HONEY
Use the honey backend.
const int DB_BACKEND_GLASS
Use the glass backend.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
const int DB_CREATE_OR_OVERWRITE
Create database if it doesn't already exist, or overwrite if it does.
include <netdb.h>, with portability workarounds.
include <sys/stat.h> with portability enhancements
<unistd.h>, but with compat.
static Xapian::Stem stemmer
#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 SKIP_TEST(MSG)
Skip 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.
#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.
bool mset_range_is_same_weights(const Xapian::MSet &mset1, unsigned int first1, const Xapian::MSet &mset2, unsigned int first2, unsigned int count)
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.
#define TEST_EXCEPTION_BASE_CLASS(TYPE, CODE)
Check that CODE throws Xapian exception derived from TYPE.
#define TEST_MSET_SIZE(M, S)
Check MSet M has size S.
void touch(const string &filename)
Touch a file, just like the Unix "touch" command.
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.