[search] Refactor Query: make variables private and add public getters.

This commit is contained in:
Yury Melnichek 2011-06-03 23:52:17 +02:00 committed by Alex Zolotarev
parent 2e1005f3b2
commit 62c19e2429
3 changed files with 16 additions and 12 deletions

View file

@ -66,9 +66,9 @@ struct FeatureProcessor
void operator () (FeatureType const & feature) const
{
KeywordMatcher matcher(MakeMatcher(m_query.m_keywords, m_query.m_prefix));
KeywordMatcher matcher(MakeMatcher(m_query.GetKeywords(), m_query.GetPrefix()));
feature.ForEachNameRef(matcher);
if (matcher.GetPrefixMatchScore() <= GetMaxPrefixMatchScore(m_query.m_prefix.size()))
if (matcher.GetPrefixMatchScore() <= GetMaxPrefixMatchScore(m_query.GetPrefix().size()))
{
uint32_t const matchScore = matcher.GetMatchScore();
if (matchScore <= GetMaxKeywordMatchScore())

View file

@ -29,12 +29,16 @@ public:
// Add result for scoring.
void AddResult(IntermediateResult const & result);
vector<strings::UniString> const & GetKeywords() const { return m_keywords; }
strings::UniString const & GetPrefix() const { return m_prefix; }
private:
string m_queryText;
m2::RectD m_rect;
vector<strings::UniString> m_keywords;
strings::UniString m_prefix;
m2::RectD m_rect;
IndexType const * m_pIndex;
IndexType::Query m_indexQuery;

View file

@ -13,16 +13,16 @@ UNIT_TEST(QueryParseKeywords_Smoke)
vector<UniString> expected;
expected.push_back(MakeUniString("minsk"));
expected.push_back(MakeUniString("belarus"));
TEST_EQUAL(expected, Query("minsk belarus ", m2::RectD(), NULL).m_keywords, ());
TEST_EQUAL(MakeUniString(""), Query("minsk belarus ", m2::RectD(), NULL).m_prefix, ());
TEST_EQUAL(expected, Query("minsk belarus ma", m2::RectD(), NULL).m_keywords, ());
TEST_EQUAL(MakeUniString("ma"), Query("minsk belarus ma", m2::RectD(), NULL).m_prefix, ());
TEST_EQUAL(expected, Query("minsk belarus ", m2::RectD(), NULL).GetKeywords(), ());
TEST_EQUAL(MakeUniString(""), Query("minsk belarus ", m2::RectD(), NULL).GetPrefix(), ());
TEST_EQUAL(expected, Query("minsk belarus ma", m2::RectD(), NULL).GetKeywords(), ());
TEST_EQUAL(MakeUniString("ma"), Query("minsk belarus ma", m2::RectD(), NULL).GetPrefix(), ());
}
UNIT_TEST(QueryParseKeywords_Empty)
{
TEST_EQUAL(vector<UniString>(), Query("", m2::RectD(), NULL).m_keywords, ());
TEST_EQUAL(MakeUniString(""), Query("", m2::RectD(), NULL).m_prefix, ());
TEST_EQUAL(vector<UniString>(), Query("Z", m2::RectD(), NULL).m_keywords, ());
TEST_EQUAL(MakeUniString("z"), Query("Z", m2::RectD(), NULL).m_prefix, ());
TEST_EQUAL(vector<UniString>(), Query("", m2::RectD(), NULL).GetKeywords(), ());
TEST_EQUAL(MakeUniString(""), Query("", m2::RectD(), NULL).GetPrefix(), ());
TEST_EQUAL(vector<UniString>(), Query("Z", m2::RectD(), NULL).GetKeywords(), ());
TEST_EQUAL(MakeUniString("z"), Query("Z", m2::RectD(), NULL).GetPrefix(), ());
}