From d05b941255c23a44cc75b0c37e5fd21f5cb418de Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 2 Aug 2011 15:14:00 +0000 Subject: [PATCH] + stub of console searcher --- src/searcher/kiwix-search.cpp | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/searcher/kiwix-search.cpp diff --git a/src/searcher/kiwix-search.cpp b/src/searcher/kiwix-search.cpp new file mode 100644 index 0000000..9e73c94 --- /dev/null +++ b/src/searcher/kiwix-search.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2011 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +enum supportedBackend { XAPIAN, CLUCENE }; + +void usage() { + cout << "Usage: kiwix-search [--verbose|-v] [--backend|-b=xapian|clucene] INDEX_PATH" << endl; + exit(1); +} + +int main(int argc, char **argv) { + + /* Init the variables */ + char *indexPath = NULL; + bool verboseFlag = false; + int option_index = 0; + int c = 0; + supportedBackend backend = XAPIAN; + + kiwix::Searcher *searcher = NULL; + + /* Argument parsing */ + while (42) { + + static struct option long_options[] = { + {"verbose", no_argument, 0, 'v'}, + {"backend", required_argument, 0, 'b'}, + {0, 0, 0, 0} + }; + + if (c != -1) { + c = getopt_long(argc, argv, "vb:", long_options, &option_index); + + switch (c) { + 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 < argc) { + if (indexPath == NULL) { + indexPath = argv[optind++]; + } else { + cout << indexPath << endl; + usage(); + } + } else { + break; + } + } + } + + /* Check if we have enough arguments */ + if (indexPath == NULL) { + usage(); + } + + /* Try to prepare the indexing */ + try { + if (backend == CLUCENE) { + searcher = new kiwix::CluceneSearcher(indexPath); + } else { + searcher = new kiwix::XapianSearcher(indexPath); + } + } catch (...) { + cerr << "Unable to search through index '" << indexPath << "'." << endl; + exit(1); + } + + /* Start the indexing */ + if (searcher != NULL) { + // while (searcher->indexNextPercent(verboseFlag)) {}; + } else { + cerr << "Unable instanciate the Kiwix searcher." << endl; + exit(1); + } + + exit(0); +}