From 94d15c51fa306308f4a216996d5532deda4df255 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 17 Aug 2011 16:51:59 +0300 Subject: [PATCH] Fix trie search. --- search/query.cpp | 27 +++++++-------------------- search/search_trie_matching.cpp | 8 +++++--- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/search/query.cpp b/search/query.cpp index ebfd01cc44..4a5068e8db 100644 --- a/search/query.cpp +++ b/search/query.cpp @@ -250,35 +250,22 @@ void Query::Search(function const & f) } // Feature matching. - FeatureProcessor featureProcessor(*this); - int const scale = scales::GetScaleLevel(m_viewport) + 1; - - try - { - m_pIndex->ForEachInRect(featureProcessor, - //m2::RectD(MercatorBounds::minX, MercatorBounds::minY, - // MercatorBounds::maxX, MercatorBounds::maxY), - m_viewport, - scales::GetUpperWorldScale()); - } - catch (FeatureProcessor::StopException &) - { - LOG(LDEBUG, ("FeatureProcessor::StopException")); - } - if (m_bTerminate) - return; - - if (scale > scales::GetUpperWorldScale()) + if (m_pTrieRoot == 0) { try { - m_pIndex->ForEachInRect(featureProcessor, m_viewport, min(scales::GetUpperScale(), scale)); + /// @todo Tune depth scale search (1 is no enough) + int const scale = min(scales::GetUpperScale(), scales::GetScaleLevel(m_viewport) + 1); + + FeatureProcessor featureProcessor(*this); + m_pIndex->ForEachInRect(featureProcessor, m_viewport, scale); } catch (FeatureProcessor::StopException &) { LOG(LDEBUG, ("FeatureProcessor::StopException")); } } + if (m_bTerminate) return; diff --git a/search/search_trie_matching.cpp b/search/search_trie_matching.cpp index 0448396e7d..376f9ca5a3 100644 --- a/search/search_trie_matching.cpp +++ b/search/search_trie_matching.cpp @@ -22,17 +22,19 @@ void search::MatchAgainstTrie(search::impl::Query & query, search::TrieIterator scoped_ptr pIter(trieRoot.Clone()); size_t symbolsMatched = 0; - while (symbolsMatched < queryS.size()) + size_t const szQuery = queryS.size(); + while (symbolsMatched < szQuery) { bool bMatched = false; for (size_t i = 0; i < pIter->m_edge.size(); ++i) { - if (pIter->m_edge[i].m_str.size() + symbolsMatched <= queryS.size() && + size_t const szEdge = pIter->m_edge[i].m_str.size(); + if (szEdge + symbolsMatched <= szQuery && equal(pIter->m_edge[i].m_str.begin(), pIter->m_edge[i].m_str.end(), queryS.begin() + symbolsMatched)) { scoped_ptr(pIter->GoToEdge(i)).swap(pIter); - symbolsMatched += queryS.size(); + symbolsMatched += szEdge; bMatched = true; break; }