From 29a981d124e4752120925216c64c13864c4c5078 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Wed, 15 Apr 2020 13:17:54 +0300 Subject: [PATCH] [search] Fix LocalityScorer similarity calculation. --- search/locality_scorer.cpp | 2 ++ .../processor_test.cpp | 25 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/search/locality_scorer.cpp b/search/locality_scorer.cpp index b84c2ccdcd..355fbf6312 100644 --- a/search/locality_scorer.cpp +++ b/search/locality_scorer.cpp @@ -3,6 +3,7 @@ #include "search/cbv.hpp" #include "search/geocoder_context.hpp" #include "search/idf_map.hpp" +#include "search/ranking_utils.hpp" #include "search/retrieval.hpp" #include "search/token_slice.hpp" #include "search/utils.hpp" @@ -267,6 +268,7 @@ void LocalityScorer::GetDocVecs(uint32_t localityId, vector & dvs) const { vector tokens; NormalizeAndTokenizeString(name, tokens); + base::EraseIf(tokens, &IsStopWord); DocVec::Builder builder; for (auto const & token : tokens) diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index 8e2322f0ff..6eaeb1229e 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -2835,7 +2835,8 @@ UNIT_CLASS_TEST(ProcessorTest, LocalityScorer) TestCity sp2(m2::PointD(2.0, 2.0), "San Pedro", "en", 50 /* rank */); TestCity sp3(m2::PointD(3.0, 3.0), "San Pedro", "en", 50 /* rank */); TestCity sp4(m2::PointD(4.0, 4.0), "San Pedro", "en", 50 /* rank */); - TestCity sp_good(m2::PointD(6.0, 6.0), "San Pedro de Atacama", "en", 100 /* rank */); + TestCity spAtacama(m2::PointD(5.5, 5.5), "San Pedro de Atacama", "en", 100 /* rank */); + TestCity spAlcantara(m2::PointD(6.5, 6.5), "San Pedro de Alcantara", "en", 40 /* rank */); auto worldId = BuildWorld([&](TestMwmBuilder & builder) { builder.Add(sp0); @@ -2843,21 +2844,31 @@ UNIT_CLASS_TEST(ProcessorTest, LocalityScorer) builder.Add(sp2); builder.Add(sp3); builder.Add(sp4); - builder.Add(sp_good); + builder.Add(spAtacama); + builder.Add(spAlcantara); }); SetViewport(m2::RectD(m2::PointD(5.0, 5.0), m2::PointD(7.0, 7.0))); { - // No results because GetToLocalities leaves sp0..sp4 even if |sp_good| has bigger rank and - // is closer to viewort center. - // sp0..sp4 are not in final results because there is no relaxed results for cities with multiple unmatched tokens. - Rules rules = {}; + Rules rules = {ExactMatch(worldId, spAtacama)}; TEST(ResultsMatch("San Pedro de Atacama ", rules), ()); } { - Rules rules = {ExactMatch(worldId, sp_good)}; + // No results because GetToLocalities leaves sp0..sp4 because sp0..sp4 and spAlcantara have + // same similarity (1.0) and sp0..sp4 have higher rank. + // sp0..sp4 are not in final results because there is no relaxed results for cities with multiple + // unmatched tokens. + Rules rules = {}; + TEST(ResultsMatch("San Pedro de Alcantara ", rules), ()); + } + { + Rules rules = {ExactMatch(worldId, spAtacama)}; TEST(ResultsMatch("Atacama ", rules), ()); } + { + Rules rules = {ExactMatch(worldId, spAlcantara)}; + TEST(ResultsMatch("Alcantara ", rules), ()); + } } } // namespace } // namespace search