Allow the opds feed to filtered by the language and "paged".

This commit is contained in:
Matthieu Gautier 2018-10-24 15:03:14 +02:00
parent f691f85724
commit 422dde9ff2
2 changed files with 23 additions and 5 deletions

View File

@ -697,17 +697,34 @@ static struct MHD_Response* handle_catalog(RequestContext* request)
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE); kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE);
} else if (url == "search") { } else if (url == "search") {
std::string query; std::string query;
std::string language;
size_t count(10);
size_t startIndex(0);
try { try {
query = request->get_argument("q"); query = request->get_argument("q");
} catch (const std::out_of_range&) { } catch (const std::out_of_range&) {}
return build_404(request, ""); try {
} language = request->get_argument("lang");
} catch (const std::out_of_range&) {}
try {
count = stoul(request->get_argument("count"));
} catch (...) {}
try {
startIndex = stoul(request->get_argument("start"));
} catch (...) {}
opdsDumper.setTitle("Search result for " + query); opdsDumper.setTitle("Search result for " + query);
uuid = zim::Uuid::generate(); uuid = zim::Uuid::generate();
bookIdsToDump = library.listBooksIds( bookIdsToDump = library.listBooksIds(
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE, kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE,
kiwix::UNSORTED, kiwix::UNSORTED,
query); query,
language);
auto totalResults = bookIdsToDump.size();
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex);
if (count>0 && bookIdsToDump.size() > count) {
bookIdsToDump.resize(count);
}
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
} else { } else {
return build_404(request, ""); return build_404(request, "");
} }

View File

@ -4,5 +4,6 @@
<Description>Search zim files in the catalog.</Description> <Description>Search zim files in the catalog.</Description>
<Url type="application/atom+xml;profile=opds-catalog" <Url type="application/atom+xml;profile=opds-catalog"
xmlns:atom="http://www.w3.org/2005/Atom" xmlns:atom="http://www.w3.org/2005/Atom"
template="/__ROOT_LOCATION__/catalog/search?q={searchTerms}"/> indexOffset="0"
template="/__ROOT_LOCATION__/catalog/search?q={searchTerms}&lang={language}&count={count}&start={startIndex}"/>
</OpenSearchDescription> </OpenSearchDescription>