An opds feed can also be the openSearch result.

We must be able to set the correct entry in the feed for a searchResult.
This commit is contained in:
Matthieu Gautier 2018-10-24 11:51:38 +02:00
parent b1508c0b98
commit c20ae18bff
2 changed files with 27 additions and 0 deletions

View File

@ -84,6 +84,15 @@ class OPDSDumper
*/ */
void setSearchDescriptionUrl(const std::string& searchDescriptionUrl) { this->searchDescriptionUrl = searchDescriptionUrl; } 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. * Set the library to dump.
* *
@ -98,6 +107,10 @@ class OPDSDumper
std::string date; std::string date;
std::string rootLocation; std::string rootLocation;
std::string searchDescriptionUrl; std::string searchDescriptionUrl;
int m_totalResults;
int m_startIndex;
int m_count;
bool m_isSearchResult = false;
private: private:
pugi::xml_node handleBook(Book book, pugi::xml_node root_node); pugi::xml_node handleBook(Book book, pugi::xml_node root_node);

View File

@ -50,6 +50,14 @@ std::string gen_date_str()
return is.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()) #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) { pugi::xml_node OPDSDumper::handleBook(Book book, pugi::xml_node root_node) {
@ -98,6 +106,12 @@ string OPDSDumper::dumpOPDSFeed(const std::vector<std::string>& bookIds)
ADD_TEXT_ENTRY(root_node, "title", title); ADD_TEXT_ENTRY(root_node, "title", title);
ADD_TEXT_ENTRY(root_node, "updated", date); 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"); auto self_link_node = root_node.append_child("link");
self_link_node.append_attribute("rel") = "self"; self_link_node.append_attribute("rel") = "self";
self_link_node.append_attribute("href") = ""; self_link_node.append_attribute("href") = "";