diff options
author | Maxim Pimenov <m@maps.me> | 2016-04-26 20:48:19 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2016-05-01 10:28:03 +0300 |
commit | 861cdb910ca40f48dbaf8e096707f0b3b912bb42 (patch) | |
tree | 9599e020017dde614929b28a07aceead73363319 /indexer/categories_index.cpp | |
parent | 0b20c90890459444778897c1fa5cd6a68538f30a (diff) |
[editor] Implemented search of a category for a newly added object.
Diffstat (limited to 'indexer/categories_index.cpp')
-rw-r--r-- | indexer/categories_index.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/indexer/categories_index.cpp b/indexer/categories_index.cpp index 0c39adc53b..50c698286b 100644 --- a/indexer/categories_index.cpp +++ b/indexer/categories_index.cpp @@ -27,11 +27,12 @@ void AddAllNonemptySubstrings(my::MemTrie<string, uint32_t> & trie, string const } } -template<typename TF> +template <typename TF> void ForEachToken(string const & s, TF && fn) { vector<strings::UniString> tokens; - SplitUniString(search::NormalizeAndSimplifyString(s), MakeBackInsertFunctor(tokens), search::Delimiters()); + SplitUniString(search::NormalizeAndSimplifyString(s), MakeBackInsertFunctor(tokens), + search::Delimiters()); for (auto const & token : tokens) fn(strings::ToUtf8(token)); } @@ -101,7 +102,7 @@ void CategoriesIndex::GetAssociatedTypes(string const & query, vector<uint32_t> { bool first = true; set<uint32_t> intersection; - ForEachToken(query, [&](string const & token) + auto processToken = [&](string const & token) { set<uint32_t> types; auto fn = [&](string const &, uint32_t type) @@ -109,6 +110,7 @@ void CategoriesIndex::GetAssociatedTypes(string const & query, vector<uint32_t> types.insert(type); }; m_trie.ForEachInSubtree(token, fn); + if (first) { intersection.swap(types); @@ -116,12 +118,14 @@ void CategoriesIndex::GetAssociatedTypes(string const & query, vector<uint32_t> else { set<uint32_t> tmp; - set_intersection(intersection.begin(),intersection.end(),types.begin(),types.end(),inserter(tmp,tmp.begin())); + set_intersection(intersection.begin(), intersection.end(), types.begin(), types.end(), + inserter(tmp, tmp.begin())); intersection.swap(tmp); } first = false; - }); - + }; + ForEachToken(query, processToken); + result.insert(result.end(), intersection.begin(), intersection.end()); } } // namespace indexer |