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