diff --git a/include/opds_dumper.h b/include/opds_dumper.h index ebfa4f8df..c4b9e9095 100644 --- a/include/opds_dumper.h +++ b/include/opds_dumper.h @@ -84,6 +84,15 @@ class OPDSDumper */ void setSearchDescriptionUrl(const std::string& searchDescriptionUrl) { this->searchDescriptionUrl = searchDescriptionUrl; } + /** + * Set some informations about the search results. + * + * @param totalResult the total number of results of the search. + * @param startIndex the start index of the result. + * @param count the number of result of the current set (or page). + */ + void setOpenSearchInfo(int totalResult, int startIndex, int count); + /** * Set the library to dump. * @@ -98,6 +107,10 @@ class OPDSDumper std::string date; std::string rootLocation; std::string searchDescriptionUrl; + int m_totalResults; + int m_startIndex; + int m_count; + bool m_isSearchResult = false; private: pugi::xml_node handleBook(Book book, pugi::xml_node root_node); diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index 1ce76b05b..fcfde0287 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -50,6 +50,14 @@ std::string gen_date_str() return is.str(); } +void OPDSDumper::setOpenSearchInfo(int totalResults, int startIndex, int count) +{ + m_totalResults = totalResults; + m_startIndex = startIndex, + m_count = count; + m_isSearchResult = true; +} + #define ADD_TEXT_ENTRY(node, child, value) (node).append_child((child)).append_child(pugi::node_pcdata).set_value((value).c_str()) pugi::xml_node OPDSDumper::handleBook(Book book, pugi::xml_node root_node) { @@ -98,6 +106,12 @@ string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds) ADD_TEXT_ENTRY(root_node, "title", title); ADD_TEXT_ENTRY(root_node, "updated", date); + if (m_isSearchResult) { + ADD_TEXT_ENTRY(root_node, "totalResults", to_string(m_totalResults)); + ADD_TEXT_ENTRY(root_node, "startIndex", to_string(m_startIndex)); + ADD_TEXT_ENTRY(root_node, "itemsPerPage", to_string(m_count)); + } + auto self_link_node = root_node.append_child("link"); self_link_node.append_attribute("rel") = "self"; self_link_node.append_attribute("href") = "";