mirror of https://github.com/kiwix/libkiwix.git
OPDS can be filtered using more than one language
From now on, the `lang` parameter of the /catalog/search, /catalog/v2/entries, and /catalog/v2/partial_entries endpoints is interpreted as a comma-separated list of languages.
This commit is contained in:
parent
c0d027e8a4
commit
7d69ece27d
|
@ -106,7 +106,15 @@ class Filter {
|
||||||
Filter& rejectTags(const Tags& tags);
|
Filter& rejectTags(const Tags& tags);
|
||||||
|
|
||||||
Filter& category(std::string category);
|
Filter& category(std::string category);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter to only accept books in the specified language.
|
||||||
|
*
|
||||||
|
* Multiple languages can be specified as a comma-separated list (in
|
||||||
|
* which case a book in any of those languages will match).
|
||||||
|
*/
|
||||||
Filter& lang(std::string lang);
|
Filter& lang(std::string lang);
|
||||||
|
|
||||||
Filter& publisher(std::string publisher);
|
Filter& publisher(std::string publisher);
|
||||||
Filter& creator(std::string creator);
|
Filter& creator(std::string creator);
|
||||||
Filter& maxSize(size_t size);
|
Filter& maxSize(size_t size);
|
||||||
|
|
|
@ -535,9 +535,20 @@ Xapian::Query categoryQuery(const std::string& category)
|
||||||
return Xapian::Query("XC" + normalizeText(category));
|
return Xapian::Query("XC" + normalizeText(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
Xapian::Query langQuery(const std::string& lang)
|
Xapian::Query langQuery(const std::string& commaSeparatedLanguageList)
|
||||||
{
|
{
|
||||||
return Xapian::Query("L" + normalizeText(lang));
|
Xapian::Query q;
|
||||||
|
bool firstIteration = true;
|
||||||
|
for ( const auto& lang : kiwix::split(commaSeparatedLanguageList, ",") ) {
|
||||||
|
const Xapian::Query singleLangQuery("L" + normalizeText(lang));
|
||||||
|
if ( firstIteration ) {
|
||||||
|
q = singleLangQuery;
|
||||||
|
firstIteration = false;
|
||||||
|
} else {
|
||||||
|
q = Xapian::Query(Xapian::Query::OP_OR, q, singleLangQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
Xapian::Query publisherQuery(const std::string& publisher)
|
Xapian::Query publisherQuery(const std::string& publisher)
|
||||||
|
|
|
@ -344,10 +344,12 @@ TEST_F(LibraryServerTest, catalog_search_by_language)
|
||||||
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
" <title>Filtered zims (lang=eng,fra)</title>\n"
|
" <title>Filtered zims (lang=eng,fra)</title>\n"
|
||||||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
" <totalResults>0</totalResults>\n"
|
" <totalResults>2</totalResults>\n"
|
||||||
" <startIndex>0</startIndex>\n"
|
" <startIndex>0</startIndex>\n"
|
||||||
" <itemsPerPage>0</itemsPerPage>\n"
|
" <itemsPerPage>2</itemsPerPage>\n"
|
||||||
CATALOG_LINK_TAGS
|
CATALOG_LINK_TAGS
|
||||||
|
RAY_CHARLES_CATALOG_ENTRY
|
||||||
|
CHARLES_RAY_CATALOG_ENTRY
|
||||||
"</feed>\n"
|
"</feed>\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -727,9 +729,11 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_language)
|
||||||
CATALOG_V2_ENTRIES_PREAMBLE("?lang=eng,fra")
|
CATALOG_V2_ENTRIES_PREAMBLE("?lang=eng,fra")
|
||||||
" <title>Filtered Entries (lang=eng,fra)</title>\n"
|
" <title>Filtered Entries (lang=eng,fra)</title>\n"
|
||||||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
" <totalResults>0</totalResults>\n"
|
" <totalResults>2</totalResults>\n"
|
||||||
" <startIndex>0</startIndex>\n"
|
" <startIndex>0</startIndex>\n"
|
||||||
" <itemsPerPage>0</itemsPerPage>\n"
|
" <itemsPerPage>2</itemsPerPage>\n"
|
||||||
|
RAY_CHARLES_CATALOG_ENTRY
|
||||||
|
CHARLES_RAY_CATALOG_ENTRY
|
||||||
"</feed>\n"
|
"</feed>\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue