40 #include <sys/types.h>
53 char *
p =
const_cast<char *
>(s.c_str());
56 bool del = (*
p ==
'!');
61 last = strtoul(
p + 1, &
p, 10);
63 if (*
p && *
p !=
' ') {
64 tout <<
p - s.c_str() <<
'\n';
65 FAIL_TEST(
"Bad sparse db spec (expected space): " << s);
68 FAIL_TEST(
"Bad sparse db spec (first > last): " << s);
76 string id =
str(first);
79 doc.
add_term(
string(first % 7 + 1,
char((first % 26) +
'a')));
82 }
while (first++ < last);
84 if (*
p ==
'\0')
break;
106 "5-7 24 76 987 1023-1027 9999 !9999");
117 "3000 999999 !999999");
266 }
else if (indb.
size() > 1) {
272 static const char*
const suffixes[] = {
273 "",
"/postlist",
"/termlist.",
nullptr
275 for (
auto s : suffixes) {
283 tout <<
"Trying suffix '" << suffix <<
"'\n";
284 string arg = outdbpath;
328 const char * stubpath =
".stub/compactstub1";
329 const char * stubpathfile =
".stub/compactstub1/XAPIANDB";
330 mkdir(
".stub", 0755);
331 mkdir(stubpath, 0755);
332 ofstream stub(stubpathfile);
333 TEST(stub.is_open());
355 const char * stubpath =
".stub/compactstub2";
356 mkdir(
".stub", 0755);
357 ofstream stub(stubpath);
358 TEST(stub.is_open());
380 const char * stubpath =
".stub/compactstub3";
381 mkdir(
".stub", 0755);
382 ofstream stub(stubpath);
383 TEST(stub.is_open());
403 const char * stubpath =
".stub/compactstub4";
404 const char * stubpathfile =
".stub/compactstub4/XAPIANDB";
405 mkdir(
".stub", 0755);
406 mkdir(stubpath, 0755);
407 ofstream stub(stubpathfile);
408 TEST(stub.is_open());
568 "5-7 24 76 987 1023-1027 9999 !9999");
574 "3000 999999 !999999");
595 int fd =
open(outdbpath.c_str(), O_CREAT|O_RDWR|
O_BINARY, 0666);
621 int fd =
open(outdbpath.c_str(), O_CREAT|O_RDWR|
O_BINARY, 0666);
623 TEST(lseek(fd, 8192, SEEK_SET) == 8192);
641 size_t n =
sizeof(buf);
643 ssize_t c = read(fd, buf, n);
645 for (
const char *
p = buf;
p != buf + c; ++
p) {
651 TEST(lseek(fd, 8192, SEEK_SET) == 8192);
738 for (
int i = 1; i < 4000; ++i) {
static void make_sparse_db(Xapian::WritableDatabase &db, const string &s)
DEFINE_TESTCASE(compactnorenumber1, compact &&!multi)
static void make_multichunk_db(Xapian::WritableDatabase &db, const string &)
static void make_missing_tables(Xapian::WritableDatabase &db, const string &)
static void make_all_tables2(Xapian::WritableDatabase &db, const string &)
static void make_all_tables(Xapian::WritableDatabase &db, const string &)
static void check_sparse_uid_terms(const string &path)
string get_database_path(const string &dbname)
Xapian::WritableDatabase get_writable_database(const string &dbname)
std::string get_compaction_output_path(const std::string &name)
Xapian::Database get_database(const string &dbname)
test functionality of the Xapian API
An indexed database of documents.
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.
void close()
Close the database.
Xapian::TermIterator spellings_begin() const
An iterator which returns all the spelling correction targets.
Xapian::TermIterator spellings_end() const noexcept
End iterator corresponding to spellings_begin().
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
size_t size() const
Return number of shards in this Database object.
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).
TermIterator allterms_end(std::string_view={}) const noexcept
End iterator corresponding to allterms_begin(prefix).
void compact(std::string_view output, unsigned flags=0, int block_size=0)
Produce a compact version of this database.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
TermIterator allterms_begin(std::string_view prefix={}) const
Start iterating all terms in the database with a given prefix.
std::string get_uuid() const
Get the UUID for the database.
Class representing a document.
void add_boolean_term(std::string_view term)
Add a boolean filter term to the document.
void set_data(std::string_view data)
Set the document data.
void add_term(std::string_view term, Xapian::termcount wdf_inc=1)
Add a term to this document.
InvalidOperationError indicates the API was used in an invalid way.
Class for iterating over a list of terms.
Class for iterating over a list of terms.
This class provides read/write access to a database.
void delete_document(Xapian::docid did)
Delete a document from the database.
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 add_spelling(std::string_view word, Xapian::termcount freqinc=1) const
Add a word to the spelling dictionary.
void commit()
Commit pending modifications.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
test database contents and consistency.
Utility functions for testing files.
bool dir_exists(const char *path)
Test if a directory exists.
bool file_exists(const char *path)
Test if a file exists.
Work around MSVC's unhelpful non-standard invalid parameter handling.
string str(int value)
Convert int to std::string.
Database open(std::string_view host, unsigned int port, unsigned timeout=10000, unsigned connect_timeout=10000)
Construct a Database object for read-only access to a remote database accessed via a TCP connection.
const int DBCOMPACT_MULTIPASS
If merging more than 3 databases, merge the postlists in multiple passes.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
const int DBCOMPACT_NO_RENUMBER
Use the same document ids in the output as in the input(s).
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
const int DBCOMPACT_SINGLE_FILE
Produce a single-file database.
include <fcntl.h>, but working around broken platforms.
include <sys/stat.h> with portability enhancements
<unistd.h>, but with compat.
Convert types to std::string.
bool startswith(std::string_view s, char pfx)
void dbcheck(const Xapian::Database &db, Xapian::doccount expected_doccount, Xapian::docid expected_lastdocid)
Check consistency of database and statistics.
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(a)
Test a condition, without an additional explanation for failure.
#define TEST_NOT_EQUAL(a, b)
Test for non-equality of two things.
Xapian-specific test helper functions and macros.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
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.