36 #define PROG_NAME "xapian-compact"
37 #define PROG_DESC "Compact a database, or merge and compact several"
41 #define OPT_NO_RENUMBER 3
44 cout <<
"Usage: " PROG_NAME " [OPTIONS] SOURCE_DATABASE... DESTINATION_DATABASE\n\n"
46 " -b, --blocksize=B Set the blocksize in bytes (e.g. 4096) or K (e.g. 4K)\n"
47 " (must be between 2K and 64K and a power of 2, default 8K)\n"
48 " -B, --backend=B Set the output backend. Supported values are 'glass'\n"
49 " and 'honey'. By default input's backend is used. At\n"
50 " present only glass to honey conversion is implemented -\n"
51 " otherwise the backend must be the same.\n"
52 " -n, --no-full Disable full compaction\n"
53 " -F, --fuller No effect for glass since Xapian 1.4.31\n"
54 " -m, --multipass If merging more than 3 databases, merge the postlists in\n"
55 " multiple passes (which is generally faster but requires\n"
56 " more disk space for temporary files)\n"
57 " --no-renumber Preserve the numbering of document ids (useful if you have\n"
58 " external references to them, or have set them to match\n"
59 " unique ids from an external source). Currently this\n"
60 " option is only supported when merging databases if they\n"
61 " have disjoint ranges of used document ids\n"
62 " -s, --single-file Produce a single file database\n"
63 " --help display this help and exit\n"
64 " --version output version information and exit\n";
75 void set_status(
const string& table,
const string& status)
override;
78 resolve_duplicate_metadata(
const string & key,
80 const string tags[])
override;
89 cout <<
'\r' << table <<
": " << status <<
'\n';
91 cout << table <<
" ..." << flush;
102 cerr <<
"Warning: duplicate user metadata key with different tag "
103 "value - picking value from first source database with a "
114 const char *
opts =
"b:B:nFmqs";
131 unsigned backend = 0;
133 unsigned block_size = 0;
140 unsigned long value = strtoul(
optarg, &
p, 10);
142 (*
p ==
'K' || *
p ==
'k')) {
149 (value & (value - 1)) != 0) {
151 "for blocksize, must be a power of 2 between "
156 block_size = unsigned(value);
160 if (strcmp(
optarg,
"honey") == 0) {
162 }
else if (strcmp(
optarg,
"glass") == 0) {
166 <<
"' passed for backend - must be 'glass' or "
208 string destdir = argv[argc - 1];
210 flags |= backend | level;
214 for (
int i =
optind; i < argc - 1; ++i) {
217 src.
compact(destdir, flags, block_size, compactor);
221 }
catch (
const char * msg) {
222 cerr << argv[0] <<
": " << msg <<
'\n';
void set_status(const string &table, const string &status) override
Update progress.
void set_quiet(bool quiet_)
string resolve_duplicate_metadata(const string &key, size_t n, const string tags[]) override
Resolve multiple user metadata entries with the same key.
Compact a database, or merge and compact several.
compaction_level
Compaction level.
@ FULL
Split items whenever it saves space (the default).
@ FULLER
Allow oversize items to save more space (not recommended if you ever plan to update the compacted dat...
@ STANDARD
Don't split items unnecessarily.
An indexed database of documents.
void add_database(const Database &other)
Add shards from another Database.
void compact(std::string_view output, unsigned flags=0, int block_size=0)
Produce a compact version of this database.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Definitions, types, etc for use inside glass.
#define GLASS_MIN_BLOCKSIZE
Minimum B-tree block size.
#define GLASS_MAX_BLOCKSIZE
Maximum B-tree block size.
Wrappers to allow GNU getopt to be used cleanly from C++ code.
#define required_argument
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
const int DBCOMPACT_MULTIPASS
If merging more than 3 databases, merge the postlists in multiple passes.
const int DB_BACKEND_HONEY
Use the honey backend.
const int DB_BACKEND_GLASS
Use the glass backend.
const int DBCOMPACT_NO_RENUMBER
Use the same document ids in the output as in the input(s).
const int DBCOMPACT_SINGLE_FILE
Produce a single-file database.
int main(int argc, char **argv)
static const struct option long_opts[]
Public interfaces for the Xapian library.