From 1ff1bf6168af7ff7891a26da00e0b415bb15f742 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 10 Aug 2017 09:18:05 -0400 Subject: [PATCH] Always set the humanReadableName with the readable in kiwix-search. We always need a humanReadableName associated with a content to search in. Do not separate the two values (human readable name and zim) in two different functions. This way, we avoid miss-use of the Searcher who could lead to segfault. --- include/searcher.h | 5 +++-- src/android/kiwix.cpp | 2 +- src/searcher.cpp | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/searcher.h b/include/searcher.h index c9db988dc..fc9c73079 100644 --- a/include/searcher.h +++ b/include/searcher.h @@ -57,7 +57,9 @@ class Searcher { public: Searcher(); - Searcher(const string& xapianDirectoryPath, Reader* reader); + Searcher(const string& xapianDirectoryPath, + Reader* reader, + const string& humanReadableName); ~Searcher(); void add_reader(Reader* reader, const std::string& humanReaderName); @@ -72,7 +74,6 @@ class Searcher bool setProtocolPrefix(const std::string prefix); bool setSearchProtocolPrefix(const std::string prefix); void reset(); - void setContentHumanReadableId(const string& contentHumanReadableId); #ifdef ENABLE_CTPP2 string getHtml(); diff --git a/src/android/kiwix.cpp b/src/android/kiwix.cpp index ba392f670..10c9bd484 100644 --- a/src/android/kiwix.cpp +++ b/src/android/kiwix.cpp @@ -514,7 +514,7 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixlib_JNIKiwix_loadFulltextIndex( } if (!reader || !reader->hasFulltextIndex()) { // Use old API (no embedded full text index). - searcher = new kiwix::Searcher(cPath, reader); + searcher = new kiwix::Searcher(cPath, reader, ""); } else { // Use the new API. We don't care about the human readable name as // we don't use it (in android). diff --git a/src/searcher.cpp b/src/searcher.cpp index aae7a5267..7ea4fa672 100644 --- a/src/searcher.cpp +++ b/src/searcher.cpp @@ -73,7 +73,9 @@ struct SearcherInternal { }; /* Constructor */ -Searcher::Searcher(const string& xapianDirectoryPath, Reader* reader) +Searcher::Searcher(const string& xapianDirectoryPath, + Reader* reader, + const string& humanReadableName) : internal(new SearcherInternal()), searchPattern(""), protocolPrefix("zim://"), @@ -88,6 +90,8 @@ Searcher::Searcher(const string& xapianDirectoryPath, Reader* reader) if (!reader || !reader->hasFulltextIndex()) { internal->_xapianSearcher = new XapianSearcher(xapianDirectoryPath, reader); } + this->contentHumanReadableId = humanReadableName; + this->humanReaderNames.push_back(humanReadableName); } Searcher::Searcher() @@ -252,11 +256,6 @@ bool Searcher::setSearchProtocolPrefix(const std::string prefix) return true; } -void Searcher::setContentHumanReadableId(const string& contentHumanReadableId) -{ - this->contentHumanReadableId = contentHumanReadableId; -} - _Result::_Result(Searcher* searcher, zim::Search::iterator& iterator) : searcher(searcher), iterator(iterator) {