From 10782a15beff13b5c3232707e6b829f2d2ec9175 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 2 Nov 2010 17:12:51 +0000 Subject: [PATCH] + add the --backend argument to be able to deal also with clucene (in additon to Xapian) --- src/indexer/kiwix-index.cpp | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index 5e9ca2c..be2bc96 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -3,8 +3,10 @@ #include #include +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);