25 #include <initializer_list>
35 #define PROG_NAME "copydatabase"
36 #define PROG_DESC "Perform a document-by-document copy of one or more Xapian databases"
41 cout <<
"Usage: " PROG_NAME " SOURCE_DATABASE... DESTINATION_DATABASE\n\n"
43 " --no-renumber Preserve the numbering of document ids (useful if you have\n"
44 " external references to them, or have set them to match\n"
45 " unique ids from an external source). If multiple source\n"
46 " databases are specified and the same docid occurs in more\n"
47 " one, the last occurrence will be the one which ends up in\n"
48 " the destination database.\n"
49 " --help display this help and exit\n"
50 " --version output version information and exit\n";
55 main(
int argc,
char **argv)
58 if (argc > 1 && argv[1][0] ==
'-') {
59 if (strcmp(argv[1],
"--help") == 0) {
63 if (strcmp(argv[1],
"--version") == 0) {
67 if (strcmp(argv[1],
"--no-renumber") == 0) {
82 const char *dest = argv[argc - 1];
85 for (
int i = 1; i < argc - 1; ++i) {
92 src.resize(src.size() - 1);
106 const char * leaf = src.c_str() + (src.find_last_of(
DIR_SEPS) + 1);
111 cout << leaf <<
": empty!\n";
114 int width =
static_cast<int>(log10(
double(dbsize))) + 1;
131 if (c <= 10 || (dbsize - c) % 13 == 0) {
132 cout <<
'\r' << leaf <<
": ";
133 cout << setw(width) << c <<
'/' << dbsize << flush;
142 cout <<
"Copying spelling data..." << flush;
150 cout <<
"Copying synonym data..." << flush;
153 string key = *synkey;
163 cout <<
"Copying user metadata..." << flush;
166 string key = *metakey;
173 cout <<
"Committing..." << flush;
An indexed database of documents.
Xapian::TermIterator metadata_keys_begin(std::string_view prefix={}) const
An iterator which returns all user-specified metadata keys.
Xapian::TermIterator synonym_keys_begin(std::string_view prefix={}) const
An iterator which returns all terms which have synonyms.
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.
Xapian::TermIterator synonyms_end(std::string_view) const noexcept
End iterator corresponding to synonyms_begin(term).
Xapian::TermIterator synonym_keys_end(std::string_view={}) const noexcept
End iterator corresponding to synonym_keys_begin(prefix).
Xapian::TermIterator metadata_keys_end(std::string_view={}) const noexcept
End iterator corresponding to metadata_keys_begin().
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::TermIterator synonyms_begin(std::string_view term) const
An iterator which returns all the synonyms for a given term.
Xapian::Document get_document(Xapian::docid did, unsigned flags=0) const
Get a document from the database.
std::string get_metadata(std::string_view key) const
Get the user-specified metadata associated with a given key.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Class for iterating over a list of terms.
Class for iterating over a list of terms.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
This class provides read/write access to a 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 set_metadata(std::string_view key, std::string_view metadata)
Set the user-specified metadata associated with a given key.
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.
static void show_usage(int rc)
int main(int argc, char **argv)
const int DB_CREATE
Create a new database.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Public interfaces for the Xapian library.