From 3bac5521d8f1c47e33b8ed13d202996b31c3ab8f Mon Sep 17 00:00:00 2001 From: Yury Melnichek Date: Sat, 4 Jun 2011 22:07:04 +0200 Subject: [PATCH] [search] Copy index in query. Fixes crashes. Still TODO to stop the search when another query comes. --- indexer/index.hpp | 23 +++++++++++++++++++++++ search/query.cpp | 2 +- search/query.hpp | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/indexer/index.hpp b/indexer/index.hpp index 7b8cf3993e..57880a8311 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -79,6 +79,19 @@ template class MultiIndexAdapter public: typedef typename IndexT::Query Query; + MultiIndexAdapter() + { + } + + MultiIndexAdapter(MultiIndexAdapter const & index) : m_indexes(index.m_indexes.size()) + { + for (size_t i = 0; i < index.m_indexes.size(); ++i) + { + CHECK(index.m_indexes[i], ()); + m_indexes[i] = index.m_indexes[i]->Clone(); + } + } + ~MultiIndexAdapter() { Clean(); @@ -282,6 +295,16 @@ private: INDEX_REMOVE = 2 }; + IndexProxy * Clone() const + { + IndexProxy * pRes = new IndexProxy(*this); + pRes->m_action = INDEX_DO_NOTHING; + pRes->m_pIndex = NULL; + pRes->m_lockCount = 0; + pRes->m_queriesSkipped = 0; + return pRes; + } + volatile IndexAction m_action; private: diff --git a/search/query.cpp b/search/query.cpp index bb3bf882bd..54e3fe708a 100644 --- a/search/query.cpp +++ b/search/query.cpp @@ -90,7 +90,7 @@ struct FeatureProcessor } // unnamed namespace Query::Query(string const & query, m2::RectD const & viewport, IndexType const * pIndex) - : m_queryText(query), m_viewport(viewport), m_pIndex(pIndex), m_bTerminate(false) + : m_queryText(query), m_viewport(viewport), m_pIndex(new IndexType(*pIndex)), m_bTerminate(false) { search::Delimiters delims; SplitAndNormalizeAndSimplifyString(query, MakeBackInsertFunctor(m_keywords), delims); diff --git a/search/query.hpp b/search/query.hpp index f76932a9e4..cb77e98d8c 100644 --- a/search/query.hpp +++ b/search/query.hpp @@ -8,6 +8,7 @@ #include "../base/string_utils.hpp" #include "../std/function.hpp" #include "../std/queue.hpp" +#include "../std/scoped_ptr.hpp" #include "../std/string.hpp" #include "../std/vector.hpp" @@ -46,7 +47,7 @@ private: vector m_keywords; strings::UniString m_prefix; - IndexType const * m_pIndex; + scoped_ptr m_pIndex; IndexType::Query m_indexQuery; priority_queue m_results;