From 3ce668af666b5e854d3faa3b6646e235adfc75a1 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 19 Dec 2017 14:17:15 +0100 Subject: [PATCH] Add a suggestion option to search in suggestion. There are two kinds of search system : - Suggestion (search in title only) - "Classical" search (search in whole content) The option `--suggestion` allow `kiwix-search` to search for suggestion. Without the option, a "classical" search is made. Fix #132. --- src/searcher/kiwix-search.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/searcher/kiwix-search.cpp b/src/searcher/kiwix-search.cpp index 3a71858..34e3bb9 100644 --- a/src/searcher/kiwix-search.cpp +++ b/src/searcher/kiwix-search.cpp @@ -37,6 +37,7 @@ int main(int argc, char** argv) const char* zimPath = NULL; const char* search = NULL; bool verboseFlag = false; + bool suggestionFlag = false; int option_index = 0; int c = 0; @@ -46,15 +47,20 @@ int main(int argc, char** argv) /* Argument parsing */ while (42) { static struct option long_options[] - = {{"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}}; + = {{"verbose", no_argument, 0, 'v'}, + {"suggestion", no_argument, 0, 's'}, + {0, 0, 0, 0}}; if (c != -1) { - c = getopt_long(argc, argv, "vb:", long_options, &option_index); + c = getopt_long(argc, argv, "vsb:", long_options, &option_index); switch (c) { case 'v': verboseFlag = true; break; + case 's': + suggestionFlag = true; + break; } } else { if (optind < argc) { @@ -100,7 +106,11 @@ int main(int argc, char** argv) /* Start the indexing */ if (searcher != NULL) { string searchString(search); - searcher->search(searchString, 0, 10, verboseFlag); + if (suggestionFlag) { + searcher->suggestions(searchString, verboseFlag); + } else { + searcher->search(searchString, 0, 10, verboseFlag); + } kiwix::Result* p_result; while ((p_result = searcher->getNextResult())) { cout << p_result->get_title() << endl;