mirror of https://github.com/kiwix/libkiwix.git
Properly set "language" parameter in `opensearch::Query` tag.
This commit is contained in:
parent
ee01859984
commit
bfcf317f09
|
@ -87,6 +87,16 @@ void SearchRenderer::setSearchProtocolPrefix(const std::string& prefix)
|
|||
this->searchProtocolPrefix = prefix;
|
||||
}
|
||||
|
||||
std::string extractValueFromQuery(const std::string& query, const std::string& key) {
|
||||
const std::string p = key + "=";
|
||||
const size_t i = query.find(p);
|
||||
if (i == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
std::string r = query.substr(i + p.size());
|
||||
return r.substr(0, r.find("&"));
|
||||
}
|
||||
|
||||
kainjow::mustache::data buildQueryData
|
||||
(
|
||||
const std::string& searchProtocolPrefix,
|
||||
|
@ -99,6 +109,10 @@ kainjow::mustache::data buildQueryData
|
|||
ss << searchProtocolPrefix << "?pattern=" << urlEncode(pattern, true);
|
||||
ss << "&" << bookQuery;
|
||||
query.set("unpaginatedQuery", ss.str());
|
||||
auto lang = extractValueFromQuery(bookQuery, "books.filter.lang");
|
||||
if(!lang.empty()) {
|
||||
query.set("lang", lang);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -499,14 +499,27 @@ TEST_F(TaskbarlessServerTest, searchResults)
|
|||
return url;
|
||||
}
|
||||
|
||||
std::string getPattern() const
|
||||
std::string extractQueryValue(const std::string& key) const
|
||||
{
|
||||
const std::string p = "pattern=";
|
||||
const std::string p = key + "=";
|
||||
const size_t i = query.find(p);
|
||||
if (i == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
std::string r = query.substr(i + p.size());
|
||||
return r.substr(0, r.find("&"));
|
||||
}
|
||||
|
||||
std::string getPattern() const
|
||||
{
|
||||
return extractQueryValue("pattern");
|
||||
}
|
||||
|
||||
std::string getLang() const
|
||||
{
|
||||
return extractQueryValue("books.filter.lang");
|
||||
}
|
||||
|
||||
std::string url() const
|
||||
{
|
||||
return makeUrl(query, start, resultsPerPage);
|
||||
|
@ -522,7 +535,7 @@ TEST_F(TaskbarlessServerTest, searchResults)
|
|||
<opensearch:itemsPerPage>ITEMCOUNT</opensearch:itemsPerPage>
|
||||
<atom:link rel="search" type="application/opensearchdescription+xml" href="/ROOT/search/searchdescription.xml"/>
|
||||
<opensearch:Query role="request"
|
||||
searchTerms="PATTERN"
|
||||
searchTerms="PATTERN"LANGQUERY
|
||||
startIndex="FIRSTRESULT"
|
||||
count="ITEMCOUNT"
|
||||
/>)";
|
||||
|
@ -533,6 +546,12 @@ TEST_F(TaskbarlessServerTest, searchResults)
|
|||
header = replace(header, "ITEMCOUNT", to_string(realResultsPerPage));
|
||||
header = replace(header, "RESULTCOUNT", to_string(totalResultCount));
|
||||
header = replace(header, "PATTERN", getPattern());
|
||||
auto queryLang = getLang();
|
||||
if (queryLang.empty()) {
|
||||
header = replace(header, "LANGQUERY", "");
|
||||
} else {
|
||||
header = replace(header, "LANGQUERY", "\n language=\""+queryLang+"\"");
|
||||
}
|
||||
return header;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue