From 41e013ca14079bde0a4ce7639b286899e33fe34d Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sun, 26 Jun 2022 16:50:00 +0300 Subject: [PATCH] [search] Match categories with possible stop-words. Signed-off-by: Viktor Govako --- search/processor.cpp | 7 ++-- .../processor_test.cpp | 35 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/search/processor.cpp b/search/processor.cpp index 3f67a94166..09d998219b 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -314,12 +314,10 @@ void Processor::SetQuery(string const & query, bool categorialRequest /* = false } } - RemoveStopWordsIfNeeded(m_tokens, m_prefix); + QuerySliceOnRawStrings const tokenSlice(m_tokens, m_prefix); // Get preferred types to show in results. m_preferredTypes.clear(); - auto const tokenSlice = QuerySliceOnRawStrings(m_tokens, m_prefix); - m_isCategorialRequest = categorialRequest; auto const locales = GetCategoryLocales(); @@ -334,6 +332,9 @@ void Processor::SetQuery(string const & query, bool categorialRequest /* = false } } + // Remove stopwords *after* FillCategories call (it makes exact tokens match). + RemoveStopWordsIfNeeded(m_tokens, m_prefix); + if (!m_isCategorialRequest) { // Assign tokens and prefix to scorer. diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index 45ce3bbbee..2c660d2d18 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -2337,7 +2337,7 @@ UNIT_CLASS_TEST(ProcessorTest, StreetNumberEnriched) } } -UNIT_CLASS_TEST(ProcessorTest, Postbox) +UNIT_CLASS_TEST(ProcessorTest, PostcodesErrorTest) { string const countryName = "Wonderland"; @@ -3053,4 +3053,37 @@ UNIT_CLASS_TEST(ProcessorTest, BurgerStreet) } } */ + +UNIT_CLASS_TEST(ProcessorTest, PostCategoryTest) +{ + string const countryName = "Wonderland"; + + TestPOI office({0, 0}, "PO", "default"); + office.SetTypes({{"amenity", "post_office"}}); + + TestPOI box({1, 1}, "PB", "default"); + box.SetTypes({{"amenity", "post_box"}}); + + TestPOI locker({2, 2}, "PL", "default"); + locker.SetTypes({{"amenity", "parcel_locker"}}); + + auto countryId = BuildCountry(countryName, [&](TestMwmBuilder & builder) + { + builder.Add(office); + builder.Add(box); + builder.Add(locker); + }); + + SetViewport(m2::RectD(0, 0, 3, 3)); + + { + Rules rules{ExactMatch(countryId, office), ExactMatch(countryId, box), ExactMatch(countryId, locker)}; + TEST(ResultsMatch("Oficina de correos", "es", rules), ()); + } + + { + Rules rules{ExactMatch(countryId, office), ExactMatch(countryId, box), ExactMatch(countryId, locker)}; + TEST(CategoryMatch("Oficina de correos", rules, "es"), ()); + } +} } // namespace processor_test