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
This commit is contained in:
Matthieu Gautier 2018-03-12 17:32:24 +01:00
parent 57a197d38d
commit f8a2e4c503
2 changed files with 11 additions and 3 deletions

View File

@ -111,8 +111,10 @@ class Searcher
* *
* @param reader The Reader for the zim containing the fulltext index. * @param reader The Reader for the zim containing the fulltext index.
* @param humanReaderName The human readable name of the reader. * @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. * Start a search on the zim associated to the Searcher.

View File

@ -118,10 +118,14 @@ Searcher::~Searcher()
delete internal; 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->readers.push_back(reader);
this->humanReaderNames.push_back(humanReadableName); this->humanReaderNames.push_back(humanReadableName);
return true;
} }
/* Search strings in the database */ /* Search strings in the database */
@ -166,7 +170,9 @@ void Searcher::search(std::string& search,
std::vector<const zim::File*> zims; std::vector<const zim::File*> zims;
for (auto current = this->readers.begin(); current != this->readers.end(); for (auto current = this->readers.begin(); current != this->readers.end();
current++) { current++) {
zims.push_back((*current)->getZimFileHandler()); if ( (*current)->hasFulltextIndex() ) {
zims.push_back((*current)->getZimFileHandler());
}
} }
zim::Search* search = new zim::Search(zims); zim::Search* search = new zim::Search(zims);
search->set_query(unaccentedSearch); search->set_query(unaccentedSearch);