mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-23 03:52:35 -04:00
Allow the opds feed to filtered by the language and "paged".
This commit is contained in:
parent
f691f85724
commit
422dde9ff2
@ -697,17 +697,34 @@ static struct MHD_Response* handle_catalog(RequestContext* request)
|
||||
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE);
|
||||
} else if (url == "search") {
|
||||
std::string query;
|
||||
std::string language;
|
||||
size_t count(10);
|
||||
size_t startIndex(0);
|
||||
try {
|
||||
query = request->get_argument("q");
|
||||
} catch (const std::out_of_range&) {
|
||||
return build_404(request, "");
|
||||
}
|
||||
} catch (const std::out_of_range&) {}
|
||||
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);
|
||||
uuid = zim::Uuid::generate();
|
||||
bookIdsToDump = library.listBooksIds(
|
||||
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE,
|
||||
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 {
|
||||
return build_404(request, "");
|
||||
}
|
||||
|
@ -4,5 +4,6 @@
|
||||
<Description>Search zim files in the catalog.</Description>
|
||||
<Url type="application/atom+xml;profile=opds-catalog"
|
||||
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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user