Merge pull request #115 from kiwix/better_search_handling

Better search handling
This commit is contained in:
Matthieu Gautier 2017-11-29 16:21:45 +00:00 committed by GitHub
commit 77d25686cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -475,10 +475,11 @@ static struct MHD_Response* handle_search(RequestContext* request)
std::string patternString;
try {
humanReadableBookId = request->get_argument("content");
} catch (const std::out_of_range&) {}
try {
patternString = request->get_argument("pattern");
} catch (const std::out_of_range&) {
return build_homepage(request);
}
} catch (const std::out_of_range&) {}
/* Retrive geo search */
bool has_geo_query = false;
@ -502,7 +503,7 @@ static struct MHD_Response* handle_search(RequestContext* request)
bool cacheEnabled = !(searcher == globalSearcher);
/* Try first to load directly the article */
if (reader != nullptr) {
if (reader != nullptr && !patternString.empty()) {
std::string patternCorrespondingUrl;
auto variants = reader->getTitleVariants(patternString);
auto variantsItr = variants.begin();
@ -522,7 +523,7 @@ static struct MHD_Response* handle_search(RequestContext* request)
}
/* Make the search */
if (reader_searcher.second != nullptr &&
if (searcher != nullptr &&
(!patternString.empty() || has_geo_query)) {
auto start = 0;
try {
@ -964,7 +965,7 @@ int main(int argc, char** argv)
readers[humanReadableId] = reader;
if ( reader->hasFulltextIndex()) {
kiwix::Searcher* searcher = new kiwix::Searcher();
kiwix::Searcher* searcher = new kiwix::Searcher(humanReadableId);
searcher->setProtocolPrefix(rootLocation + "/");
searcher->setSearchProtocolPrefix(rootLocation + "/" + "search?");
searcher->add_reader(reader, humanReadableId);