forked from organicmaps/organicmaps-tmp
[search] Fix ranking for strasse.
This commit is contained in:
parent
98b31651d1
commit
6802cfd3e0
2 changed files with 69 additions and 11 deletions
|
@ -55,6 +55,37 @@ void UpdateNameScores(vector<strings::UniString> const & tokens, Slice const & s
|
|||
bestScores.m_errorsMade = ErrorsMade::Min(bestScores.m_errorsMade, GetErrorsMade(tokens, slice));
|
||||
}
|
||||
|
||||
// This function assumes that at most one token in |streetTokens| ends with "strasse".
|
||||
bool ModifyStrasse(vector<strings::UniString> & streetTokens)
|
||||
{
|
||||
auto static const kStrasse = strings::MakeUniString("strasse");
|
||||
for (size_t i = 0; i < streetTokens.size(); ++i)
|
||||
{
|
||||
auto & token = streetTokens[i];
|
||||
if (strings::EndsWith(token, kStrasse))
|
||||
{
|
||||
if (token == kStrasse)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
streetTokens[i - 1] = streetTokens[i - 1] + kStrasse;
|
||||
streetTokens.erase(streetTokens.begin() + i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
streetTokens[i] =
|
||||
strings::UniString(streetTokens[i].begin(), streetTokens[i].end() - kStrasse.size());
|
||||
streetTokens.insert(streetTokens.begin() + i + 1, kStrasse);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
NameScores GetNameScores(FeatureType & ft, Geocoder::Params const & params,
|
||||
TokenRange const & range, Model::Type type)
|
||||
{
|
||||
|
@ -79,6 +110,12 @@ NameScores GetNameScores(FeatureType & ft, Geocoder::Params const & params,
|
|||
|
||||
UpdateNameScores(tokens, slice, bestScores);
|
||||
UpdateNameScores(tokens, sliceNoCategories, bestScores);
|
||||
|
||||
if (type == Model::TYPE_STREET && ModifyStrasse(tokens))
|
||||
{
|
||||
UpdateNameScores(tokens, slice, bestScores);
|
||||
UpdateNameScores(tokens, sliceNoCategories, bestScores);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == Model::TYPE_BUILDING)
|
||||
|
|
|
@ -1965,7 +1965,7 @@ UNIT_CLASS_TEST(ProcessorTest, StreetSynonymPrefix)
|
|||
}
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(ProcessorTest, StrasseIndexing)
|
||||
UNIT_CLASS_TEST(ProcessorTest, Strasse)
|
||||
{
|
||||
string const countryName = "Wonderland";
|
||||
|
||||
|
@ -1979,22 +1979,43 @@ UNIT_CLASS_TEST(ProcessorTest, StrasseIndexing)
|
|||
builder.Add(s2);
|
||||
});
|
||||
|
||||
auto checkNoErrors = [&](string const & query, Rules const & rules) {
|
||||
auto request = MakeRequest(query, "en");
|
||||
auto const & results = request->Results();
|
||||
|
||||
TEST(ResultsMatch(results, rules), (query));
|
||||
TEST_EQUAL(results.size(), 1, (query));
|
||||
TEST_EQUAL(results[0].GetRankingInfo().m_errorsMade, ErrorsMade(0), (query));
|
||||
auto const nameScore = results[0].GetRankingInfo().m_nameScore;
|
||||
TEST(nameScore == NAME_SCORE_FULL_MATCH || nameScore == NAME_SCORE_PREFIX, (query));
|
||||
};
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(0.0, 0.0), m2::PointD(1.0, 2.0)));
|
||||
{
|
||||
Rules rules = {ExactMatch(countryId, s1)};
|
||||
TEST(ResultsMatch("abcdstrasse", rules), ());
|
||||
TEST(ResultsMatch("abcdstraße", rules), ());
|
||||
TEST(ResultsMatch("abcd strasse", rules), ());
|
||||
TEST(ResultsMatch("abcd straße", rules), ());
|
||||
TEST(ResultsMatch("abcd", rules), ());
|
||||
checkNoErrors("abcdstrasse ", rules);
|
||||
checkNoErrors("abcdstrasse", rules);
|
||||
checkNoErrors("abcdstraße ", rules);
|
||||
checkNoErrors("abcdstraße", rules);
|
||||
checkNoErrors("abcd strasse ", rules);
|
||||
checkNoErrors("abcd strasse", rules);
|
||||
checkNoErrors("abcd straße ", rules);
|
||||
checkNoErrors("abcd straße", rules);
|
||||
checkNoErrors("abcd ", rules);
|
||||
checkNoErrors("abcd", rules);
|
||||
}
|
||||
{
|
||||
Rules rules = {ExactMatch(countryId, s2)};
|
||||
TEST(ResultsMatch("xyzstrasse", rules), ());
|
||||
TEST(ResultsMatch("xyzstraße", rules), ());
|
||||
TEST(ResultsMatch("xyz strasse", rules), ());
|
||||
TEST(ResultsMatch("xyz straße", rules), ());
|
||||
TEST(ResultsMatch("xyz", rules), ());
|
||||
checkNoErrors("xyzstrasse ", rules);
|
||||
checkNoErrors("xyzstrasse", rules);
|
||||
checkNoErrors("xyzstraße ", rules);
|
||||
checkNoErrors("xyzstraße", rules);
|
||||
checkNoErrors("xyz strasse ", rules);
|
||||
checkNoErrors("xyz strasse", rules);
|
||||
checkNoErrors("xyz straße ", rules);
|
||||
checkNoErrors("xyz straße", rules);
|
||||
checkNoErrors("xyz ", rules);
|
||||
checkNoErrors("xyz", rules);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Reference in a new issue