mirror of https://github.com/kiwix/libkiwix.git
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
This commit is contained in:
parent
4a01303438
commit
071e9e3fec
|
@ -2,6 +2,8 @@ kiwix-lib 8.2.3
|
||||||
===============
|
===============
|
||||||
|
|
||||||
* [OPDS] Correctly set the id of the OPDS stream.
|
* [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
|
kiwix-lib 8.2.2
|
||||||
===============
|
===============
|
||||||
|
|
|
@ -750,17 +750,16 @@ Response InternalServer::handle_catalog(const RequestContext& request)
|
||||||
uuid = zim::Uuid::generate(host);
|
uuid = zim::Uuid::generate(host);
|
||||||
bookIdsToDump = mp_library->filter(kiwix::Filter().valid(true).local(true).remote(true));
|
bookIdsToDump = mp_library->filter(kiwix::Filter().valid(true).local(true).remote(true));
|
||||||
} else if (url == "search") {
|
} else if (url == "search") {
|
||||||
std::string query;
|
auto filter = kiwix::Filter().valid(true).local(true).remote(true);
|
||||||
std::string language;
|
string query("<Empty query>");
|
||||||
std::vector<std::string> tags;
|
|
||||||
std::vector<std::string> noTags;
|
|
||||||
size_t count(10);
|
size_t count(10);
|
||||||
size_t startIndex(0);
|
size_t startIndex(0);
|
||||||
try {
|
try {
|
||||||
query = request.get_argument("q");
|
query = request.get_argument("q");
|
||||||
|
filter.query(query);
|
||||||
} catch (const std::out_of_range&) {}
|
} catch (const std::out_of_range&) {}
|
||||||
try {
|
try {
|
||||||
language = request.get_argument("lang");
|
filter.lang(request.get_argument("lang"));
|
||||||
} catch (const std::out_of_range&) {}
|
} catch (const std::out_of_range&) {}
|
||||||
try {
|
try {
|
||||||
count = extractFromString<unsigned long>(request.get_argument("count"));
|
count = extractFromString<unsigned long>(request.get_argument("count"));
|
||||||
|
@ -769,20 +768,14 @@ Response InternalServer::handle_catalog(const RequestContext& request)
|
||||||
startIndex = extractFromString<unsigned long>(request.get_argument("start"));
|
startIndex = extractFromString<unsigned long>(request.get_argument("start"));
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
try {
|
try {
|
||||||
tags = kiwix::split(request.get_argument("notag"), ";");
|
filter.acceptTags(kiwix::split(request.get_argument("notag"), ";"));
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
try {
|
try {
|
||||||
noTags = kiwix::split(request.get_argument("notag"), ";");
|
filter.rejectTags(kiwix::split(request.get_argument("notag"), ";"));
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
opdsDumper.setTitle("Search result for " + query);
|
opdsDumper.setTitle("Search result for " + query);
|
||||||
uuid = zim::Uuid::generate();
|
uuid = zim::Uuid::generate();
|
||||||
bookIdsToDump = mp_library->filter(
|
bookIdsToDump = mp_library->filter(filter);
|
||||||
kiwix::Filter().valid(true).local(true).remote(true)
|
|
||||||
.query(query)
|
|
||||||
.lang(language)
|
|
||||||
.acceptTags(tags)
|
|
||||||
.rejectTags(noTags)
|
|
||||||
);
|
|
||||||
auto totalResults = bookIdsToDump.size();
|
auto totalResults = bookIdsToDump.size();
|
||||||
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex);
|
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex);
|
||||||
if (count>0 && bookIdsToDump.size() > count) {
|
if (count>0 && bookIdsToDump.size() > count) {
|
||||||
|
|
Loading…
Reference in New Issue