File tree 5 files changed +34
-5
lines changed
5 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ class Library
154
154
155
155
public:
156
156
typedef std::vector<std::string> BookIdCollection;
157
+ typedef std::map<std::string, int > AttributeCounts;
157
158
158
159
public:
159
160
Library ();
@@ -242,6 +243,13 @@ class Library
242
243
*/
243
244
std::vector<std::string> getBooksLanguages () const ;
244
245
246
+ /* *
247
+ * Get all languagues of the books in the library with counts.
248
+ *
249
+ * @return A list of languages with the count of books in each language.
250
+ */
251
+ AttributeCounts getBooksLanguagesWithCounts () const ;
252
+
245
253
/* *
246
254
* Get all categories of the books in the library.
247
255
*
@@ -345,6 +353,7 @@ class Library
345
353
typedef const std::string& (Book::*BookStrPropMemFn)() const ;
346
354
347
355
private: // functions
356
+ AttributeCounts getBookAttributeCounts (BookStrPropMemFn p) const ;
348
357
std::vector<std::string> getBookPropValueSet (BookStrPropMemFn p) const ;
349
358
BookIdCollection filterViaBookDB (const Filter& filter) const ;
350
359
void updateBookDB (const Book& book);
Original file line number Diff line number Diff line change @@ -208,25 +208,38 @@ bool Library::writeBookmarksToFile(const std::string& path) const
208
208
return writeTextFile (path, dumper.dumpLibXMLBookmark ());
209
209
}
210
210
211
- std::vector<std::string> Library::getBookPropValueSet (BookStrPropMemFn p) const
211
+ Library::AttributeCounts Library::getBookAttributeCounts (BookStrPropMemFn p) const
212
212
{
213
- std::set<std::string> propValues ;
213
+ AttributeCounts propValueCounts ;
214
214
215
215
for (const auto & pair: m_books) {
216
216
const auto & book = pair.second ;
217
217
if (book.getOrigId ().empty ()) {
218
- propValues. insert (( book.*p)()) ;
218
+ propValueCounts[( book.*p)()] += 1 ;
219
219
}
220
220
}
221
+ return propValueCounts;
222
+ }
221
223
222
- return std::vector<std::string>(propValues.begin (), propValues.end ());
224
+ std::vector<std::string> Library::getBookPropValueSet (BookStrPropMemFn p) const
225
+ {
226
+ std::vector<std::string> result;
227
+ for ( const auto & kv : getBookAttributeCounts (p) ) {
228
+ result.push_back (kv.first );
229
+ }
230
+ return result;
223
231
}
224
232
225
233
std::vector<std::string> Library::getBooksLanguages () const
226
234
{
227
235
return getBookPropValueSet (&Book::getLanguage);
228
236
}
229
237
238
+ Library::AttributeCounts Library::getBooksLanguagesWithCounts () const
239
+ {
240
+ return getBookAttributeCounts (&Book::getLanguage);
241
+ }
242
+
230
243
std::vector<std::string> Library::getBooksCategories () const
231
244
{
232
245
std::set<std::string> categories;
Original file line number Diff line number Diff line change @@ -160,11 +160,14 @@ std::string OPDSDumper::languagesOPDSFeed() const
160
160
{
161
161
const auto now = gen_date_str ();
162
162
kainjow::mustache::list languageData;
163
- for ( const auto & languageCode : library->getBooksLanguages () ) {
163
+ for ( const auto & langAndBookCount : library->getBooksLanguagesWithCounts () ) {
164
+ const std::string languageCode = langAndBookCount.first ;
165
+ const int bookCount = langAndBookCount.second ;
164
166
const auto languageSelfName = getLanguageSelfName (languageCode);
165
167
languageData.push_back (kainjow::mustache::object{
166
168
{" lang_code" , languageCode},
167
169
{" lang_self_name" , languageSelfName},
170
+ {" book_count" , to_string (bookCount)},
168
171
{" updated" , now},
169
172
{" id" , gen_uuid (libraryId + " /languages/" + languageCode)}
170
173
});
Original file line number Diff line number Diff line change 16
16
<entry >
17
17
<title >{{lang_self_name}}</title >
18
18
<dc : language >{{{lang_code}}}</dc : language >
19
+ <thr : count >{{book_count}}</thr : count >
19
20
<link rel =" subsection"
20
21
href =" {{endpoint_root}}/entries?lang={{{lang_code}}}"
21
22
type =" application/atom+xml;profile=opds-catalog;kind=acquisition" />
Original file line number Diff line number Diff line change @@ -1035,6 +1035,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
1035
1035
<entry>
1036
1036
<title>English</title>
1037
1037
<dc:language>eng</dc:language>
1038
+ <thr:count>1</thr:count>
1038
1039
<link rel="subsection"
1039
1040
href="/catalog/v2/entries?lang=eng"
1040
1041
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
@@ -1044,6 +1045,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
1044
1045
<entry>
1045
1046
<title>français</title>
1046
1047
<dc:language>fra</dc:language>
1048
+ <thr:count>1</thr:count>
1047
1049
<link rel="subsection"
1048
1050
href="/catalog/v2/entries?lang=fra"
1049
1051
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
@@ -1053,6 +1055,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
1053
1055
<entry>
1054
1056
<title>русский</title>
1055
1057
<dc:language>rus</dc:language>
1058
+ <thr:count>1</thr:count>
1056
1059
<link rel="subsection"
1057
1060
href="/catalog/v2/entries?lang=rus"
1058
1061
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
You can’t perform that action at this time.
0 commit comments