diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 52b5960e6..4dd343274 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -668,6 +668,22 @@ std::unique_ptr InternalServer::handle_catalog(const RequestContext& r uuid = zim::Uuid::generate(host); bookIdsToDump = mp_library->filter(kiwix::Filter().valid(true).local(true).remote(true)); } else if (url == "search") { + bookIdsToDump = search_catalog(request, opdsDumper); + uuid = zim::Uuid::generate(); + } + + opdsDumper.setId(kiwix::to_string(uuid)); + auto response = ContentResponse::build( + *this, + opdsDumper.dumpOPDSFeed(bookIdsToDump), + "application/atom+xml; profile=opds-catalog; kind=acquisition; charset=utf-8"); + return std::move(response); +} + +std::vector +InternalServer::search_catalog(const RequestContext& request, + kiwix::OPDSDumper& opdsDumper) +{ auto filter = kiwix::Filter().valid(true).local(true).remote(true); string query(""); size_t count(10); @@ -698,22 +714,14 @@ std::unique_ptr InternalServer::handle_catalog(const RequestContext& r filter.rejectTags(kiwix::split(request.get_argument("notag"), ";")); } catch (...) {} opdsDumper.setTitle("Search result for " + query); - uuid = zim::Uuid::generate(); - bookIdsToDump = mp_library->filter(filter); + std::vector bookIdsToDump = mp_library->filter(filter); 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()); - } - - opdsDumper.setId(kiwix::to_string(uuid)); - auto response = ContentResponse::build( - *this, - opdsDumper.dumpOPDSFeed(bookIdsToDump), - "application/atom+xml; profile=opds-catalog; kind=acquisition; charset=utf-8"); - return std::move(response); + return bookIdsToDump; } namespace diff --git a/src/server/internalServer.h b/src/server/internalServer.h index 19720df41..318f4d426 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -41,6 +41,7 @@ namespace kiwix { typedef kainjow::mustache::data MustacheData; class Entry; +class OPDSDumper; class InternalServer { public: @@ -79,6 +80,9 @@ class InternalServer { std::unique_ptr handle_captured_external(const RequestContext& request); std::unique_ptr handle_content(const RequestContext& request); + std::vector search_catalog(const RequestContext& request, + kiwix::OPDSDumper& opdsDumper); + MustacheData get_default_data() const; MustacheData homepage_data() const;