mirror of https://github.com/kiwix/libkiwix.git
Languages OPDS feed includes book counts
This commit is contained in:
parent
45adda44b3
commit
ab3095745e
|
@ -154,6 +154,7 @@ class Library
|
|||
|
||||
public:
|
||||
typedef std::vector<std::string> BookIdCollection;
|
||||
typedef std::map<std::string, int> AttributeCounts;
|
||||
|
||||
public:
|
||||
Library();
|
||||
|
@ -242,6 +243,13 @@ class Library
|
|||
*/
|
||||
std::vector<std::string> getBooksLanguages() const;
|
||||
|
||||
/**
|
||||
* Get all languagues of the books in the library with counts.
|
||||
*
|
||||
* @return A list of languages with the count of books in each language.
|
||||
*/
|
||||
AttributeCounts getBooksLanguagesWithCounts() const;
|
||||
|
||||
/**
|
||||
* Get all categories of the books in the library.
|
||||
*
|
||||
|
@ -345,6 +353,7 @@ private: // types
|
|||
typedef const std::string& (Book::*BookStrPropMemFn)() const;
|
||||
|
||||
private: // functions
|
||||
AttributeCounts getBookAttributeCounts(BookStrPropMemFn p) const;
|
||||
std::vector<std::string> getBookPropValueSet(BookStrPropMemFn p) const;
|
||||
BookIdCollection filterViaBookDB(const Filter& filter) const;
|
||||
void updateBookDB(const Book& book);
|
||||
|
|
|
@ -208,18 +208,26 @@ bool Library::writeBookmarksToFile(const std::string& path) const
|
|||
return writeTextFile(path, dumper.dumpLibXMLBookmark());
|
||||
}
|
||||
|
||||
std::vector<std::string> Library::getBookPropValueSet(BookStrPropMemFn p) const
|
||||
Library::AttributeCounts Library::getBookAttributeCounts(BookStrPropMemFn p) const
|
||||
{
|
||||
std::set<std::string> propValues;
|
||||
AttributeCounts propValueCounts;
|
||||
|
||||
for (const auto& pair: m_books) {
|
||||
const auto& book = pair.second;
|
||||
if (book.getOrigId().empty()) {
|
||||
propValues.insert((book.*p)());
|
||||
propValueCounts[(book.*p)()] += 1;
|
||||
}
|
||||
}
|
||||
return propValueCounts;
|
||||
}
|
||||
|
||||
return std::vector<std::string>(propValues.begin(), propValues.end());
|
||||
std::vector<std::string> Library::getBookPropValueSet(BookStrPropMemFn p) const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
for ( const auto& kv : getBookAttributeCounts(p) ) {
|
||||
result.push_back(kv.first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> Library::getBooksLanguages() const
|
||||
|
@ -227,6 +235,11 @@ std::vector<std::string> Library::getBooksLanguages() const
|
|||
return getBookPropValueSet(&Book::getLanguage);
|
||||
}
|
||||
|
||||
Library::AttributeCounts Library::getBooksLanguagesWithCounts() const
|
||||
{
|
||||
return getBookAttributeCounts(&Book::getLanguage);
|
||||
}
|
||||
|
||||
std::vector<std::string> Library::getBooksCategories() const
|
||||
{
|
||||
std::set<std::string> categories;
|
||||
|
|
|
@ -160,11 +160,14 @@ std::string OPDSDumper::languagesOPDSFeed() const
|
|||
{
|
||||
const auto now = gen_date_str();
|
||||
kainjow::mustache::list languageData;
|
||||
for ( const auto& languageCode : library->getBooksLanguages() ) {
|
||||
for ( const auto& langAndBookCount : library->getBooksLanguagesWithCounts() ) {
|
||||
const std::string languageCode = langAndBookCount.first;
|
||||
const int bookCount = langAndBookCount.second;
|
||||
const auto languageSelfName = getLanguageSelfName(languageCode);
|
||||
languageData.push_back(kainjow::mustache::object{
|
||||
{"lang_code", languageCode},
|
||||
{"lang_self_name", languageSelfName},
|
||||
{"book_count", to_string(bookCount)},
|
||||
{"updated", now},
|
||||
{"id", gen_uuid(libraryId + "/languages/" + languageCode)}
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<entry>
|
||||
<title>{{lang_self_name}}</title>
|
||||
<dc:language>{{{lang_code}}}</dc:language>
|
||||
<thr:count>{{book_count}}</thr:count>
|
||||
<link rel="subsection"
|
||||
href="{{endpoint_root}}/entries?lang={{{lang_code}}}"
|
||||
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
|
|
|
@ -1035,6 +1035,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
|
|||
<entry>
|
||||
<title>English</title>
|
||||
<dc:language>eng</dc:language>
|
||||
<thr:count>1</thr:count>
|
||||
<link rel="subsection"
|
||||
href="/catalog/v2/entries?lang=eng"
|
||||
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
|
@ -1044,6 +1045,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
|
|||
<entry>
|
||||
<title>français</title>
|
||||
<dc:language>fra</dc:language>
|
||||
<thr:count>1</thr:count>
|
||||
<link rel="subsection"
|
||||
href="/catalog/v2/entries?lang=fra"
|
||||
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
|
@ -1053,6 +1055,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
|
|||
<entry>
|
||||
<title>русский</title>
|
||||
<dc:language>rus</dc:language>
|
||||
<thr:count>1</thr:count>
|
||||
<link rel="subsection"
|
||||
href="/catalog/v2/entries?lang=rus"
|
||||
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
|
|
Loading…
Reference in New Issue