34 #define PROG_NAME "xapian-compact" 35 #define PROG_DESC "Compact a database, or merge and compact several" 39 #define OPT_NO_RENUMBER 3 42 cout <<
"Usage: " PROG_NAME " [OPTIONS] SOURCE_DATABASE... DESTINATION_DATABASE\n\n" 44 " -b, --blocksize=B Set the blocksize in bytes (e.g. 4096) or K (e.g. 4K)\n" 45 " (must be between 2K and 64K and a power of 2, default 8K)\n" 46 " -n, --no-full Disable full compaction\n" 47 " -F, --fuller Enable fuller compaction (not recommended if you plan to\n" 48 " update the compacted database)\n" 49 " -m, --multipass If merging more than 3 databases, merge the postlists in\n" 50 " multiple passes (which is generally faster but requires\n" 51 " more disk space for temporary files)\n" 52 " --no-renumber Preserve the numbering of document ids (useful if you have\n" 53 " external references to them, or have set them to match\n" 54 " unique ids from an external source). Currently this\n" 55 " option is only supported when merging databases if they\n" 56 " have disjoint ranges of used document ids\n" 57 " -s, --single-file Produce a single file database (not supported for chert)\n" 58 " --help display this help and exit\n" 59 " --version output version information and exit\n";
70 void set_status(
const string& table,
const string& status)
override;
73 resolve_duplicate_metadata(
const string & key,
75 const string tags[])
override;
84 cout <<
'\r' << table <<
": " << status <<
'\n';
86 cout << table <<
" ..." << flush;
96 if (tags[0] != tags[n]) {
97 cerr <<
"Warning: duplicate user metadata key with different tag " 98 "value - picking value from first source database with a " 109 const char *
opts =
"b:nFmqs";
110 static const struct option long_opts[] = {
126 size_t block_size = 0;
133 block_size = strtoul(
optarg, &p, 10);
134 if (block_size <= 64 && (*p ==
'K' || *p ==
'k')) {
138 if (*p || block_size < 2048 || block_size > 65536 ||
139 (block_size & (block_size - 1)) != 0) {
141 <<
"' passed for blocksize, must be a power of 2 " 142 "between 2K and 64K\n";
184 string destdir = argv[argc - 1];
188 for (
int i =
optind; i < argc - 1; ++i) {
191 src.
compact(destdir, level | flags, block_size, compactor);
195 }
catch (
const char * msg) {
196 cerr << argv[0] <<
": " << msg <<
'\n';
Wrappers to allow GNU getopt to be used cleanly from C++ code.
This class is used to access a database, or a group of databases.
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
Allow oversize items to save more space (not recommended if you ever plan to update the compacted dat...
void set_quiet(bool quiet_)
int main(int argc, char **argv)
Don't split items unnecessarily.
const int DBCOMPACT_NO_RENUMBER
Use the same document ids in the output as in the input(s).
Public interfaces for the Xapian library.
Compact a database, or merge and compact several.
string resolve_duplicate_metadata(const string &key, size_t n, const string tags[]) override
Resolve multiple user metadata entries with the same key.
#define required_argument
Split items whenever it saves space (the default).
void compact(const std::string &output, unsigned flags=0, int block_size=0)
Produce a compact version of this database.
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
std::string get_description() const
Return a string describing this object.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
compaction_level
Compaction level.
const int DBCOMPACT_MULTIPASS
If merging more than 3 databases, merge the postlists in multiple passes.
const int DBCOMPACT_SINGLE_FILE
Produce a single-file database.
void set_status(const string &table, const string &status) override
Update progress.