From 8e4dd0f39d3dd124b7f9a4314271e7b22cbf8751 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 22 Jan 2014 13:54:27 +0300 Subject: [PATCH] [search] Factor out feature::IsHouseNumber to separate files. --- indexer/feature_impl.cpp | 38 ++++++++++++++++++++++++++++++++++++++ indexer/feature_impl.hpp | 7 +++++++ indexer/indexer.pro | 1 + search/search_query.cpp | 36 ++++++------------------------------ 4 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 indexer/feature_impl.cpp diff --git a/indexer/feature_impl.cpp b/indexer/feature_impl.cpp new file mode 100644 index 0000000000..bcac11206c --- /dev/null +++ b/indexer/feature_impl.cpp @@ -0,0 +1,38 @@ +#include "feature_impl.hpp" + +#include "../base/string_utils.hpp" + + +namespace feature +{ + +bool IsDigit(int c) +{ + return (c <= 127 && isdigit(c)); +} + +bool IsNumber(strings::UniString const & s) +{ + for (size_t i = 0; i < s.size(); ++i) + { + // android production ndk-r8d has bug. "еда" detected as a number. + if (!IsDigit(s[i])) + return false; + } + return true; +} + +/// Check that token can be house number. +bool IsHouseNumber(strings::UniString const & s) +{ + size_t const count = s.size(); + /// @todo Probably, call some check function from House:: + return (count > 0 && count < 8 && IsDigit(s[0])); +} + +bool IsHouseNumber(string const & s) +{ + return (!s.empty() && IsDigit(s[0])); +} + +} diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index b6472bce6c..4d3b453f26 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -1,10 +1,13 @@ #pragma once #include "../base/macros.hpp" +#include "../base/assert.hpp" #include "../std/string.hpp" +namespace strings { class UniString; } + namespace feature { static int const g_arrWorldScales[] = { 3, 5, 7, 9 }; // 9 = scales::GetUpperWorldScale() @@ -24,4 +27,8 @@ namespace feature str += arrChar[ind]; return str; } + + bool IsNumber(strings::UniString const & s); + bool IsHouseNumber(strings::UniString const & s); + bool IsHouseNumber(string const & s); } diff --git a/indexer/indexer.pro b/indexer/indexer.pro index b1483f1eb1..d5b1661308 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -42,6 +42,7 @@ SOURCES += \ string_file.cpp \ feature_algo.cpp \ mwm_version.cpp \ + feature_impl.cpp \ HEADERS += \ feature.hpp \ diff --git a/search/search_query.cpp b/search/search_query.cpp index 06e3f56a50..22a089815d 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -5,6 +5,7 @@ #include "../storage/country_info.hpp" +#include "../indexer/feature_impl.hpp" #include "../indexer/feature_covering.hpp" #include "../indexer/features_vector.hpp" #include "../indexer/index.hpp" @@ -301,30 +302,6 @@ void Query::SearchCoordinates(string const & query, Results & res) const } } -namespace -{ - -bool IsNumber(strings::UniString const & s) -{ - for (size_t i = 0; i < s.size(); ++i) - { - // android production ndk-r8d has bug. "еда" detected as a number. - if (s[i] > 127 || !isdigit(s[i])) - return false; - } - return true; -} - -/// Check that token can be house number. -bool IsHouseNumber(strings::UniString const & s) -{ - size_t const count = s.size(); - /// @todo Probably, call some check function from House:: - return (count > 0 && count < 8 && s[0] <= 127 && isdigit(s[0])); -} - -} - void Query::Search(Results & res, bool searchAddress) { ClearQueues(); @@ -333,18 +310,17 @@ void Query::Search(Results & res, bool searchAddress) SuggestStrings(res); #ifdef HOUSE_SEARCH_TEST - if (m_tokens.size() > 1 && IsHouseNumber(m_tokens.back())) + /// @todo Select best token for house number. + if (m_tokens.size() > 1 && feature::IsHouseNumber(m_tokens.back())) { m_house.swap(m_tokens.back()); m_tokens.pop_back(); } - else if (IsHouseNumber(m_prefix)) + else if (feature::IsHouseNumber(m_prefix)) { m_house.swap(m_prefix); m_prefix.clear(); } - else - m_houseDetector.ClearCaches(); #endif if (m_cancel) return; @@ -562,7 +538,7 @@ void Query::FlushResults(Results & res, void (Results::*pAddFn)(Result const &)) return; #ifdef HOUSE_SEARCH_TEST - if (!m_house.empty()) + if (!m_house.empty() && !streets.empty()) { if (m_houseDetector.LoadStreets(streets) > 0) m_houseDetector.MergeStreets(); @@ -1000,7 +976,7 @@ namespace void operator() (Query::Params::StringT const & s, size_t i) { /// @todo Do smart filtering of house numbers and zipcodes. - if (IsNumber(s)) + if (feature::IsNumber(s)) m_vec.push_back(i); } };