mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Preventing confusion of tongues in multizim search
Multizim search requires that all selected books be in the same language. No new URL query parameter was introduced for specifying the intended search language - `books.filter.lang` can be used for that purpose. The server_search unit-test was updated to use a slightly cheating library xml file where the language of example.zim was tweaked from "en" to "eng" in order to match that of zimfile.zim. Note that this change drops from the tested server two other goofy ZIM files corner_cases.zim and poor.zim that have been/are included in ServerTest.
This commit is contained in:
@ -211,6 +211,16 @@ void checkBookNumber(const Library::BookIdSet& bookIds, size_t limit) {
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::set<std::string> Languages;
|
||||
|
||||
Languages getLanguages(const Library& lib, const Library::BookIdSet& bookIds) {
|
||||
Languages langs;
|
||||
for ( const auto& b : bookIds ) {
|
||||
langs.insert(lib.getBookById(b).getLanguage());
|
||||
}
|
||||
return langs;
|
||||
}
|
||||
|
||||
struct CustomizedResourceData
|
||||
{
|
||||
std::string mimeType;
|
||||
@ -306,6 +316,10 @@ SearchInfo InternalServer::getSearchInfo(const RequestContext& request) const
|
||||
{
|
||||
auto bookIds = selectBooks(request);
|
||||
checkBookNumber(bookIds.second, m_multizimSearchLimit);
|
||||
if ( getLanguages(*mp_library, bookIds.second).size() != 1 ) {
|
||||
throw Error(nonParameterizedMessage("confusion-of-tongues"));
|
||||
}
|
||||
|
||||
auto pattern = request.get_optional_param<std::string>("pattern", "");
|
||||
GeoQuery geoQuery;
|
||||
|
||||
|
Reference in New Issue
Block a user