diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 088f3cc..6150a10 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -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, ""); } diff --git a/static/server/opensearchdescription.xml b/static/server/opensearchdescription.xml index 27c67e9..1f29bc6 100644 --- a/static/server/opensearchdescription.xml +++ b/static/server/opensearchdescription.xml @@ -4,5 +4,6 @@ Search zim files in the catalog. + indexOffset="0" + template="/__ROOT_LOCATION__/catalog/search?q={searchTerms}&lang={language}&count={count}&start={startIndex}"/>