From 071e9e3fec1cc28961ad28064745047c587b1d74 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 7 Jan 2020 17:08:39 +0100 Subject: [PATCH] Correctly filter the catalog when we don't what to filter. Set the different filter's fields only when we are requested to filter them. Else, we ends to requests that some fields are empty. If the request has no argument, we raise an exception (catched) and so we don't set the corresponding field in the filter. Fix #303 --- ChangeLog | 2 ++ src/server.cpp | 21 +++++++-------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2e542550..b50297a02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ kiwix-lib 8.2.3 =============== * [OPDS] Correctly set the id of the OPDS stream. + * [OPDS] Do not try to filter the catalog if no filter field is given in the + request. kiwix-lib 8.2.2 =============== diff --git a/src/server.cpp b/src/server.cpp index 7ff57360a..fe33181b1 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -750,17 +750,16 @@ Response InternalServer::handle_catalog(const RequestContext& request) uuid = zim::Uuid::generate(host); bookIdsToDump = mp_library->filter(kiwix::Filter().valid(true).local(true).remote(true)); } else if (url == "search") { - std::string query; - std::string language; - std::vector tags; - std::vector noTags; + auto filter = kiwix::Filter().valid(true).local(true).remote(true); + string query(""); size_t count(10); size_t startIndex(0); try { query = request.get_argument("q"); + filter.query(query); } catch (const std::out_of_range&) {} try { - language = request.get_argument("lang"); + filter.lang(request.get_argument("lang")); } catch (const std::out_of_range&) {} try { count = extractFromString(request.get_argument("count")); @@ -769,20 +768,14 @@ Response InternalServer::handle_catalog(const RequestContext& request) startIndex = extractFromString(request.get_argument("start")); } catch (...) {} try { - tags = kiwix::split(request.get_argument("notag"), ";"); + filter.acceptTags(kiwix::split(request.get_argument("notag"), ";")); } catch (...) {} try { - noTags = kiwix::split(request.get_argument("notag"), ";"); + filter.rejectTags(kiwix::split(request.get_argument("notag"), ";")); } catch (...) {} opdsDumper.setTitle("Search result for " + query); uuid = zim::Uuid::generate(); - bookIdsToDump = mp_library->filter( - kiwix::Filter().valid(true).local(true).remote(true) - .query(query) - .lang(language) - .acceptTags(tags) - .rejectTags(noTags) - ); + bookIdsToDump = mp_library->filter(filter); auto totalResults = bookIdsToDump.size(); bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex); if (count>0 && bookIdsToDump.size() > count) {