41 #include <sys/types.h> 54 char * p =
const_cast<char *
>(s.c_str());
57 bool del = (*p ==
'!');
62 last = strtoul(p + 1, &p, 10);
64 if (*p && *p !=
' ') {
65 tout << p - s.c_str() <<
'\n';
66 FAIL_TEST(
"Bad sparse db spec (expected space): " << s);
69 FAIL_TEST(
"Bad sparse db spec (first > last): " << s);
77 string id =
str(first);
80 doc.
add_term(
string(first % 7 + 1,
char((first % 26) +
'a')));
83 }
while (first++ < last);
85 if (*p ==
'\0')
break;
107 "5-7 24 76 987 1023-1027 9999 !9999");
118 "3000 999999 !999999");
267 }
else if (indb.
size() > 1) {
273 static const char*
const suffixes[] = {
274 "",
"/postlist",
"/termlist.",
nullptr 276 for (
auto s : suffixes) {
282 suffix =
"/record.DB";
288 tout <<
"Trying suffix '" << suffix <<
"'\n";
289 string arg = outdbpath;
333 const char * stubpath =
".stub/compactstub1";
334 const char * stubpathfile =
".stub/compactstub1/XAPIANDB";
335 mkdir(
".stub", 0755);
336 mkdir(stubpath, 0755);
337 ofstream stub(stubpathfile);
338 TEST(stub.is_open());
360 const char * stubpath =
".stub/compactstub2";
361 mkdir(
".stub", 0755);
362 ofstream stub(stubpath);
363 TEST(stub.is_open());
385 const char * stubpath =
".stub/compactstub3";
386 mkdir(
".stub", 0755);
387 ofstream stub(stubpath);
388 TEST(stub.is_open());
408 const char * stubpath =
".stub/compactstub4";
409 const char * stubpathfile =
".stub/compactstub4/XAPIANDB";
410 mkdir(
".stub", 0755);
411 mkdir(stubpath, 0755);
412 ofstream stub(stubpathfile);
413 TEST(stub.is_open());
573 "5-7 24 76 987 1023-1027 9999 !9999");
579 "3000 999999 !999999");
601 int fd =
open(outdbpath.c_str(), O_CREAT|O_RDWR|
O_BINARY, 0666);
628 int fd =
open(outdbpath.c_str(), O_CREAT|O_RDWR|
O_BINARY, 0666);
630 TEST(lseek(fd, 8192, SEEK_SET) == 8192);
648 size_t n =
sizeof(buf);
650 ssize_t c = read(fd, buf, n);
652 for (
const char * p = buf; p != buf + c; ++p) {
658 TEST(lseek(fd, 8192, SEEK_SET) == 8192);
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to 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.
void dbcheck(const Xapian::Database &db, Xapian::doccount expected_doccount, Xapian::docid expected_lastdocid)
Check consistency of database and statistics.
#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.
Work around MSVC's unhelpful non-standard invalid parameter handling.
test database contents and consistency.
static void make_missing_tables(Xapian::WritableDatabase &db, const string &)
InvalidOperationError indicates the API was used in an invalid way.
TermIterator allterms_end(const std::string &=std::string()) const
Corresponding end iterator to allterms_begin(prefix).
Xapian::WritableDatabase get_writable_database(const string &dbname)
a generic test suite engine
C++ function versions of useful Unix commands.
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
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.
const int DBCOMPACT_NO_RENUMBER
Use the same document ids in the output as in the input(s).
Xapian::doccount get_doccount() const
Get the number of documents in the database.
include <sys/stat.h> with portability enhancements
test functionality of the Xapian API
void rm_rf(const string &filename)
Remove a directory and contents, just like the Unix "rm -rf" command.
static void make_all_tables2(Xapian::WritableDatabase &db, const string &)
Class for iterating over a list of terms.
Class for iterating over a list of terms.
#define TEST_NOT_EQUAL(a, b)
Test for non-equality of two things.
string get_database_path(const string &dbname)
This class provides read/write access to a database.
Xapian::TermIterator spellings_begin() const
An iterator which returns all the spelling correction targets.
static void make_all_tables(Xapian::WritableDatabase &db, const string &)
std::ostringstream tout
The debug printing stream.
Public interfaces for the Xapian library.
Xapian::TermIterator synonym_keys_begin(const std::string &prefix=std::string()) const
An iterator which returns all terms which have synonyms.
static void make_multichunk_db(Xapian::WritableDatabase &db, const string &)
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.
void commit()
Commit any pending modifications made to the database.
bool startswith(const std::string &s, char pfx)
TermIterator allterms_begin(const std::string &prefix=std::string()) const
An iterator which runs across all terms with a given prefix.
void compact(const std::string &output, unsigned flags=0, int block_size=0)
Produce a compact version of this database.
bool dir_exists(const char *path)
Test if a directory exists.
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
DEFINE_TESTCASE(compactnorenumber1, compact &&!multi)
size_t size() const
Return number of shards in this Database object.
std::string get_compaction_output_path(const std::string &name)
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
Xapian::Database get_database(const string &dbname)
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Xapian-specific test helper functions and macros.
const int DBCOMPACT_MULTIPASS
If merging more than 3 databases, merge the postlists in multiple passes.
<unistd.h>, but with compat.
void add_boolean_term(const std::string &term)
Add a boolean filter term to the document.
Xapian::TermIterator spellings_end() const
Corresponding end iterator to spellings_begin().
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.
static void check_sparse_uid_terms(const string &path)
#define TEST_EQUAL(a, b)
Test for equality of two things.
const int DBCOMPACT_SINGLE_FILE
Produce a single-file database.
void set_data(const std::string &data)
Set data stored in the document.
bool file_exists(const char *path)
Test if a file exists.
virtual void close()
Close the database.
include <fcntl.h>, but working around broken platforms.
A handle representing a document in a Xapian database.
std::string get_uuid() const
Get a UUID for the database.
void add_spelling(const std::string &word, Xapian::termcount freqinc=1) const
Add a word to the spelling dictionary.
PostingIterator postlist_begin(const std::string &tname) const
An iterator pointing to the start of the postlist for a given term.
void touch(const string &filename)
Touch a file, just like the Unix "touch" command.
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.
static void make_sparse_db(Xapian::WritableDatabase &db, const string &s)