From f8a2e4c50323fd8981f2d01adadf64b7ec85902c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 12 Mar 2018 17:32:24 +0100 Subject: [PATCH] Only add a reader to the searcher if the reader as fulltext index. `libzim` will not search in zim file without embedded fulltext index. If we don't want to mess up with result index, we must not store "wrong" reader. Fix #111 --- include/searcher.h | 4 +++- src/searcher.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/searcher.h b/include/searcher.h index 9362f8b6e..52b65bb2e 100644 --- a/include/searcher.h +++ b/include/searcher.h @@ -111,8 +111,10 @@ class Searcher * * @param reader The Reader for the zim containing the fulltext index. * @param humanReaderName The human readable name of the reader. + * @return true if the reader has been added. + * false if the reader cannot be added (no embedded fulltext index present) */ - void add_reader(Reader* reader, const std::string& humanReaderName); + bool add_reader(Reader* reader, const std::string& humanReaderName); /** * Start a search on the zim associated to the Searcher. diff --git a/src/searcher.cpp b/src/searcher.cpp index c7c6222f3..61f97d686 100644 --- a/src/searcher.cpp +++ b/src/searcher.cpp @@ -118,10 +118,14 @@ Searcher::~Searcher() delete internal; } -void Searcher::add_reader(Reader* reader, const std::string& humanReadableName) +bool Searcher::add_reader(Reader* reader, const std::string& humanReadableName) { + if (!reader->hasFulltextIndex()) { + return false; + } this->readers.push_back(reader); this->humanReaderNames.push_back(humanReadableName); + return true; } /* Search strings in the database */ @@ -166,7 +170,9 @@ void Searcher::search(std::string& search, std::vector zims; for (auto current = this->readers.begin(); current != this->readers.end(); current++) { - zims.push_back((*current)->getZimFileHandler()); + if ( (*current)->hasFulltextIndex() ) { + zims.push_back((*current)->getZimFileHandler()); + } } zim::Search* search = new zim::Search(zims); search->set_query(unaccentedSearch);