mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 11:22:38 -04:00
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.
This commit is contained in:
parent
2b69cc8ffc
commit
3ce668af66
@ -37,6 +37,7 @@ int main(int argc, char** argv)
|
|||||||
const char* zimPath = NULL;
|
const char* zimPath = NULL;
|
||||||
const char* search = NULL;
|
const char* search = NULL;
|
||||||
bool verboseFlag = false;
|
bool verboseFlag = false;
|
||||||
|
bool suggestionFlag = false;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
@ -46,15 +47,20 @@ int main(int argc, char** argv)
|
|||||||
/* Argument parsing */
|
/* Argument parsing */
|
||||||
while (42) {
|
while (42) {
|
||||||
static struct option long_options[]
|
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) {
|
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) {
|
switch (c) {
|
||||||
case 'v':
|
case 'v':
|
||||||
verboseFlag = true;
|
verboseFlag = true;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
suggestionFlag = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
@ -100,7 +106,11 @@ int main(int argc, char** argv)
|
|||||||
/* Start the indexing */
|
/* Start the indexing */
|
||||||
if (searcher != NULL) {
|
if (searcher != NULL) {
|
||||||
string searchString(search);
|
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;
|
kiwix::Result* p_result;
|
||||||
while ((p_result = searcher->getNextResult())) {
|
while ((p_result = searcher->getNextResult())) {
|
||||||
cout << p_result->get_title() << endl;
|
cout << p_result->get_title() << endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user