[search] Simple category scoring by minimal prefix to show category name.

This commit is contained in:
Yury Melnichek 2011-06-18 18:08:19 +02:00 committed by Alex Zolotarev
parent 4b21f08765
commit 3e09ca0c85
4 changed files with 12 additions and 5 deletions

View file

@ -4,7 +4,7 @@ ru:2банкомат|наличка
amenity-bank
en:bank
ru:банк
ru:1банк
amenity-bar|amenity-pub
en:1bar|pub|beer

View file

@ -37,9 +37,9 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
m_direction = ResultDirection(viewportRect.Center(), m_rect.Center());
}
IntermediateResult::IntermediateResult(string name, string completionString)
IntermediateResult::IntermediateResult(string name, string completionString, int penalty)
: m_str(name), m_completionString(completionString),
m_matchPenalty(0), m_minVisibleScale(0), m_distance(0), m_direction(0),
m_matchPenalty(0), m_minVisibleScale(penalty), m_distance(0), m_direction(0),
m_resultType(RESULT_CATEGORY)
{
}

View file

@ -28,7 +28,7 @@ public:
IntermediateResult(m2::RectD const & viewportRect, double lat, double lon, double precision);
// For RESULT_CATEGORY.
IntermediateResult(string name, string completionString);
IntermediateResult(string name, string completionString, int penalty);
bool operator < (IntermediateResult const & o) const;

View file

@ -157,8 +157,15 @@ void Query::Search(function<void (Result const &)> const & f)
if (matcher.GetPrefixMatchScore() <= GetMaxPrefixMatchScore(m_prefix.size()) &&
matcher.GetMatchScore() <= GetMaxKeywordMatchScore())
{
int minPrefixMatchLength = 0;
for (vector<Category::Name>::const_iterator iName = iCategory->m_synonyms.begin();
iName != iCategory->m_synonyms.end(); ++iName)
if (iName->m_Name == matcher.GetBestMatchName())
minPrefixMatchLength = iName->m_prefixLengthToSuggest;
AddResult(IntermediateResult(matcher.GetBestMatchName(),
matcher.GetBestMatchName() + ' '));
matcher.GetBestMatchName() + ' ',
minPrefixMatchLength));
}
}
}