diff options
author | Yuri Gorshenin <y@maps.me> | 2016-04-20 15:46:11 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-04-22 17:32:49 +0300 |
commit | f48c3e6a6a55501908279b73c39089ca0e04f01e (patch) | |
tree | 90b735c24256bf483e72ffd967f91cbad25f1704 /search/search_tests | |
parent | ca9a3693b9c246c88881173f3b0cd56ee26fc0b5 (diff) |
[search] Postcodes are added to the search index.
Diffstat (limited to 'search/search_tests')
-rw-r--r-- | search/search_tests/postcodes_matcher_tests.cpp | 72 | ||||
-rw-r--r-- | search/search_tests/ranking_tests.cpp | 1 | ||||
-rw-r--r-- | search/search_tests/search_tests.pro | 1 |
3 files changed, 74 insertions, 0 deletions
diff --git a/search/search_tests/postcodes_matcher_tests.cpp b/search/search_tests/postcodes_matcher_tests.cpp new file mode 100644 index 0000000000..79013bc289 --- /dev/null +++ b/search/search_tests/postcodes_matcher_tests.cpp @@ -0,0 +1,72 @@ +#include "../../testing/testing.hpp" + +#include "search/search_query_params.hpp" +#include "search/v2/postcodes_matcher.hpp" +#include "search/v2/tokens_slice.hpp" + +#include "indexer/search_delimiters.hpp" +#include "indexer/search_string_utils.hpp" + +#include "base/stl_add.hpp" +#include "base/string_utils.hpp" + +#include "std/string.hpp" +#include "std/vector.hpp" + +using namespace strings; + +namespace search +{ +namespace v2 +{ +namespace +{ +bool LooksLikePostcode(string const & s, bool checkPrefix) +{ + vector<UniString> tokens; + bool const lastTokenIsPrefix = + TokenizeStringAndCheckIfLastTokenIsPrefix(s, tokens, search::Delimiters()); + + size_t const numTokens = tokens.size(); + + SearchQueryParams params; + if (checkPrefix && lastTokenIsPrefix) + { + params.m_prefixTokens.push_back(tokens.back()); + tokens.pop_back(); + } + + for (auto const & token : tokens) + { + params.m_tokens.emplace_back(); + params.m_tokens.back().push_back(token); + } + + return LooksLikePostcode(TokensSlice(params, 0, numTokens)); +} + +UNIT_TEST(PostcodesMatcher_Smoke) +{ + TEST(LooksLikePostcode("141701", false /* checkPrefix */), ()); + TEST(LooksLikePostcode("141", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("BA6 8JP", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("BA6 8JP", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("BA22 9HR", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("BA22", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("DE56 4FW", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("NY 1000", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("AZ 85203", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("AZ", true /* checkPrefix */), ()); + + TEST(LooksLikePostcode("803 0271", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("803-0271", true /* checkPrefix */), ()); + TEST(LooksLikePostcode("〒803-0271", true /* checkPrefix */), ()); + + TEST(!LooksLikePostcode("1 мая", true /* checkPrefix */), ()); + TEST(!LooksLikePostcode("1 мая улица", true /* checkPrefix */), ()); + TEST(!LooksLikePostcode("москва", true /* checkPrefix */), ()); + TEST(!LooksLikePostcode("39 с 79", true /* checkPrefix */), ()); +} +} // namespace +} // namespace v2 +} // namespace search diff --git a/search/search_tests/ranking_tests.cpp b/search/search_tests/ranking_tests.cpp index b74e35a284..37a2b15da0 100644 --- a/search/search_tests/ranking_tests.cpp +++ b/search/search_tests/ranking_tests.cpp @@ -2,6 +2,7 @@ #include "search/search_query_params.hpp" #include "search/v2/ranking_utils.hpp" +#include "search/v2/tokens_slice.hpp" #include "indexer/search_delimiters.hpp" #include "indexer/search_string_utils.hpp" diff --git a/search/search_tests/search_tests.pro b/search/search_tests/search_tests.pro index a0b8b8538b..92ff99f8fe 100644 --- a/search/search_tests/search_tests.pro +++ b/search/search_tests/search_tests.pro @@ -27,6 +27,7 @@ SOURCES += \ latlon_match_test.cpp \ locality_finder_test.cpp \ locality_scorer_test.cpp \ + postcodes_matcher_tests.cpp \ query_saver_tests.cpp \ ranking_tests.cpp \ string_intersection_test.cpp \ |