diff --git a/search/feature_offset_match.hpp b/search/feature_offset_match.hpp index ab1c1233ac..961102725a 100644 --- a/search/feature_offset_match.hpp +++ b/search/feature_offset_match.hpp @@ -329,18 +329,13 @@ void MatchPostcodesInTrie(TokenSlice const & slice, trie::Iterator co impl::OffsetIntersector intersector(filter); for (size_t i = 0; i < slice.Size(); ++i) { - if (slice.IsPrefix(i)) - { - std::vector> dfas; - slice.Get(i).ForEach([&dfas](UniString const & s) { dfas.emplace_back(UniStringDFA(s)); }); - MatchInTrie(dfas, TrieRootPrefix(*postcodesRoot, edge), intersector); - } - else - { - std::vector dfas; - slice.Get(i).ForEach([&dfas](UniString const & s) { dfas.emplace_back(s); }); - MatchInTrie(dfas, TrieRootPrefix(*postcodesRoot, edge), intersector); - } + // Full match required even for prefix token. Reasons: + // 1. For postcode every symbol is important, partial matching can lead to wrong results. + // 2. For prefix match query like "streetname 40" where |streetname| is located in 40xxx + // postcode zone will give all street vicinity as the result which is wrong. + std::vector dfas; + slice.Get(i).ForEach([&dfas](UniString const & s) { dfas.emplace_back(s); }); + MatchInTrie(dfas, TrieRootPrefix(*postcodesRoot, edge), intersector); intersector.NextStep(); } diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index 11fc40a90a..978824389c 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -728,12 +728,10 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) } { - string const kQueries[] = {"london WC2H 7BX", "london WC2H 7", "london WC2H ", "london WC"}; - for (auto const & query : kQueries) - { - Rules rules{ExactMatch(countryId, building1)}; - TEST(ResultsMatch(query, rules), (query)); - } + Rules rules{ExactMatch(countryId, building1)}; + TEST(ResultsMatch("london WC2H 7BX", rules), ()); + TEST(!ResultsMatch("london WC2H 7", rules), ()); + TEST(!ResultsMatch("london WC", rules), ()); } }