+ add the --backend argument to be able to deal also with clucene (in additon to Xapian)

This commit is contained in:
kelson42 2010-11-02 17:12:51 +00:00
parent f3882f19f5
commit 10782a15be

View File

@ -3,8 +3,10 @@
#include <kiwix/xapianIndexer.h>
#include <kiwix/cluceneIndexer.h>
enum supportedBackend { XAPIAN, CLUCENE };
void usage() {
cout << "Usage: kiwix-index [--verbose|-v] ZIM_PATH INDEX_PATH" << endl;
cout << "Usage: kiwix-index [--verbose|-v] [--backend|-b=xapian|clucene] ZIM_PATH INDEX_PATH" << endl;
exit(1);
}
@ -12,20 +14,23 @@ int main(int argc, char **argv) {
/* Init the variables */
char *zimFilePath = NULL;
char *xapianDirectoryPath = NULL;
char *indexPath = NULL;
bool verboseFlag = false;
int option_index = 0;
kiwix::XapianIndexer *indexer = NULL;
supportedBackend backend = XAPIAN;
kiwix::Indexer *indexer = NULL;
/* Argument parsing */
while (42) {
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{"backend", required_argument, 0, 'b'},
{0, 0, 0, 0}
};
int c = getopt_long(argc, argv, "v", long_options, &option_index);
int c = getopt_long(argc, argv, "vb:", long_options, &option_index);
if (c != -1) {
@ -33,13 +38,22 @@ int main(int argc, char **argv) {
case 'v':
verboseFlag = true;
break;
case 'b':
if (!strcmp(optarg, "clucene")) {
backend = CLUCENE;
} else if (!strcmp(optarg, "xapian")) {
backend = XAPIAN;
} else {
usage();
}
break;
}
} else {
if (optind + option_index < argc) {
if (argc > 2 && optind + option_index - 1 < argc) {
if (zimFilePath == NULL) {
zimFilePath = argv[optind + option_index];
} else if (xapianDirectoryPath == NULL) {
xapianDirectoryPath = argv[optind + option_index];
zimFilePath = argv[optind + option_index - 1];
} else if (indexPath == NULL) {
indexPath = argv[optind + option_index - 1];
} else {
usage();
}
@ -48,17 +62,20 @@ int main(int argc, char **argv) {
}
option_index++;
}
}
/* Check if we have enough arguments */
if (zimFilePath == NULL || xapianDirectoryPath == NULL) {
if (zimFilePath == NULL || indexPath == NULL) {
usage();
}
/* Try to prepare the indexing */
try {
indexer = new kiwix::XapianIndexer(zimFilePath, xapianDirectoryPath);
if (backend == CLUCENE) {
indexer = new kiwix::XapianIndexer(zimFilePath, indexPath);
} else {
indexer = new kiwix::CluceneIndexer(zimFilePath, indexPath);
}
} catch (...) {
cerr << "Unable to index '" << zimFilePath << "'." << endl;
exit(1);