Extracted InternalServer::search_catalog()

This commit is contained in:
Veloman Yunkan 2021-03-03 14:36:38 +04:00
parent f270724b1f
commit 80d4f7e349
2 changed files with 22 additions and 10 deletions

View File

@ -668,6 +668,22 @@ std::unique_ptr<Response> InternalServer::handle_catalog(const RequestContext& r
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") {
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<std::string>
InternalServer::search_catalog(const RequestContext& request,
kiwix::OPDSDumper& opdsDumper)
{
auto filter = kiwix::Filter().valid(true).local(true).remote(true); auto filter = kiwix::Filter().valid(true).local(true).remote(true);
string query("<Empty query>"); string query("<Empty query>");
size_t count(10); size_t count(10);
@ -698,22 +714,14 @@ std::unique_ptr<Response> InternalServer::handle_catalog(const RequestContext& r
filter.rejectTags(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(); std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
bookIdsToDump = mp_library->filter(filter);
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) {
bookIdsToDump.resize(count); bookIdsToDump.resize(count);
} }
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size()); opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
} return bookIdsToDump;
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);
} }
namespace namespace

View File

@ -41,6 +41,7 @@ namespace kiwix {
typedef kainjow::mustache::data MustacheData; typedef kainjow::mustache::data MustacheData;
class Entry; class Entry;
class OPDSDumper;
class InternalServer { class InternalServer {
public: public:
@ -79,6 +80,9 @@ class InternalServer {
std::unique_ptr<Response> handle_captured_external(const RequestContext& request); std::unique_ptr<Response> handle_captured_external(const RequestContext& request);
std::unique_ptr<Response> handle_content(const RequestContext& request); std::unique_ptr<Response> handle_content(const RequestContext& request);
std::vector<std::string> search_catalog(const RequestContext& request,
kiwix::OPDSDumper& opdsDumper);
MustacheData get_default_data() const; MustacheData get_default_data() const;
MustacheData homepage_data() const; MustacheData homepage_data() const;