3
0
Fork 0

Use the kiwix::Reader instead of kiwix::Searcher to search suggestion.

The expected behavior from a user pov, is that suggestions return titles
starting with the searchPattern if no fulltext index is available.

`kiwix::Searcher` works only on a xapian database.
So `kiwix::Searcher::suggestions` will return results only if a embedded
fulltext is available.

This is `kiwix::Reader::searchSuggestionsSmart` that first try to do a
search with `kiwix::Searcher` and they fallback to titles starting with
the searchPattern.
better_search_tool
Matthieu Gautier 8 years ago
parent 426796dc37
commit ba0708d052

@ -98,6 +98,19 @@ int main(int argc, char** argv)
* directory */ * directory */
} }
string searchString(search);
if (suggestionFlag) {
if (!reader) {
cerr << "Unable to open zim '" << zimPath << "'." << endl;
exit(1);
}
reader->searchSuggestionsSmart(searchString, 10);
std::string title;
while (reader->getNextSuggestion(title)) {
cout << title << endl;
}
} else {
if (reader) { if (reader) {
searcher = new kiwix::Searcher(); searcher = new kiwix::Searcher();
searcher->add_reader(reader, ""); searcher->add_reader(reader, "");
@ -112,10 +125,6 @@ int main(int argc, char** argv)
/* Start the indexing */ /* Start the indexing */
if (searcher != NULL) { if (searcher != NULL) {
string searchString(search);
if (suggestionFlag) {
searcher->suggestions(searchString, verboseFlag);
} else {
searcher->search(searchString, 0, 10, verboseFlag); searcher->search(searchString, 0, 10, verboseFlag);
} }
kiwix::Result* p_result; kiwix::Result* p_result;
@ -123,15 +132,10 @@ int main(int argc, char** argv)
cout << p_result->get_title() << endl; cout << p_result->get_title() << endl;
delete p_result; delete p_result;
} }
}
delete searcher; delete searcher;
delete reader; delete reader;
// kiwix::XapianSearcher::terminate();
} else {
cerr << "Unable instanciate the Kiwix searcher." << endl;
exit(1);
}
exit(0); exit(0);
} }

Loading…
Cancel
Save