forked from organicmaps/organicmaps
[search] Match categories on feature types.
This commit is contained in:
parent
36e1eefb8d
commit
c1c3aaca50
2 changed files with 25 additions and 2 deletions
|
@ -81,7 +81,22 @@ struct FeatureProcessor
|
|||
MYTHROW(StopException, ());
|
||||
}
|
||||
|
||||
KeywordMatcher matcher(MakeMatcher(m_query.GetKeywords(), m_query.GetPrefix()));
|
||||
uint32_t keywordsSkipMask = 0;
|
||||
FeatureType::GetTypesFn types;
|
||||
feature.ForEachTypeRef(types);
|
||||
for (int i = 0; i < types.m_size; ++i)
|
||||
keywordsSkipMask |= m_query.GetKeywordsToSkipForType(types.m_types[i]);
|
||||
|
||||
// TODO: Make faster.
|
||||
vector<strings::UniString> const & queryKeywords = m_query.GetKeywords();
|
||||
ASSERT_LESS(queryKeywords.size(), 32, ());
|
||||
vector<strings::UniString> keywords;
|
||||
keywords.reserve(queryKeywords.size());
|
||||
for (size_t i = 0; i < queryKeywords.size() && i < 32; ++i)
|
||||
if (!(keywordsSkipMask & (1 << i)))
|
||||
keywords.push_back(queryKeywords[i]);
|
||||
|
||||
KeywordMatcher matcher(MakeMatcher(keywords, m_query.GetPrefix()));
|
||||
feature.ForEachNameRef(matcher);
|
||||
if (matcher.GetPrefixMatchScore() <= GetMaxPrefixMatchScore(m_query.GetPrefix().size()))
|
||||
{
|
||||
|
@ -288,5 +303,13 @@ void Query::AddResult(IntermediateResult const & result)
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t Query::GetKeywordsToSkipForType(uint32_t const type) const
|
||||
{
|
||||
unordered_map<uint32_t, uint32_t>::const_iterator it = m_keywordsToSkipForType.find(type);
|
||||
if (it == m_keywordsToSkipForType.end())
|
||||
return 0;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // namespace search::impl
|
||||
} // namespace search
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
m2::RectD const & GetViewport() const { return m_viewport; }
|
||||
vector<strings::UniString> const & GetKeywords() const { return m_keywords; }
|
||||
strings::UniString const & GetPrefix() const { return m_prefix; }
|
||||
uint32_t GetKeywordsToSkipForType(uint32_t const type) const;
|
||||
|
||||
private:
|
||||
string m_queryText;
|
||||
|
@ -58,7 +59,6 @@ private:
|
|||
|
||||
vector<strings::UniString> m_keywords;
|
||||
unordered_map<uint32_t, uint32_t> m_keywordsToSkipForType;
|
||||
vector<vector<uint32_t> > m_keywordCategories;
|
||||
strings::UniString m_prefix;
|
||||
|
||||
scoped_ptr<IndexType const> m_pIndex;
|
||||
|
|
Loading…
Add table
Reference in a new issue