mirror of https://github.com/kiwix/libkiwix.git
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:
parent
57a197d38d
commit
f8a2e4c503
|
@ -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.
|
||||||
|
|
|
@ -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,8 +170,10 @@ 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++) {
|
||||||
|
if ( (*current)->hasFulltextIndex() ) {
|
||||||
zims.push_back((*current)->getZimFileHandler());
|
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);
|
||||||
search->set_range(resultStart, resultEnd);
|
search->set_range(resultStart, resultEnd);
|
||||||
|
|
Loading…
Reference in New Issue