diff --git a/android/jni/com/mapswithme/maps/SearchEngine.cpp b/android/jni/com/mapswithme/maps/SearchEngine.cpp index 012daed463..f12fc63c53 100644 --- a/android/jni/com/mapswithme/maps/SearchEngine.cpp +++ b/android/jni/com/mapswithme/maps/SearchEngine.cpp @@ -181,12 +181,16 @@ extern "C" } JNIEXPORT void JNICALL - Java_com_mapswithme_maps_search_SearchEngine_nativeRunInteractiveSearch(JNIEnv * env, jclass clazz, jbyteArray bytes, jstring lang, jlong timestamp) + Java_com_mapswithme_maps_search_SearchEngine_nativeRunInteractiveSearch(JNIEnv * env, jclass clazz, jbyteArray bytes, + jstring lang, jlong timestamp, jboolean viewportOnly) { search::SearchParams params; params.m_query = jni::ToNativeString(env, bytes); params.SetInputLocale(ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang))); params.m_callback = bind(&OnResults, _1, timestamp, true, false, 0, 0); + if (viewportOnly) + params.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY | search::SearchParams::SEARCH_WORLD); + g_framework->NativeFramework()->StartInteractiveSearch(params); g_framework->NativeFramework()->UpdateUserViewportChanged(); g_queryTimestamp = timestamp; diff --git a/android/src/com/mapswithme/maps/search/SearchEngine.java b/android/src/com/mapswithme/maps/search/SearchEngine.java index 088a165dd9..7c50298da5 100644 --- a/android/src/com/mapswithme/maps/search/SearchEngine.java +++ b/android/src/com/mapswithme/maps/search/SearchEngine.java @@ -77,11 +77,11 @@ public enum SearchEngine implements NativeSearchListener return false; } - public static void runInteractiveSearch(String query, String language, long timestamp) + public static void runInteractiveSearch(String query, String language, long timestamp, boolean viewportOnly) { try { - nativeRunInteractiveSearch(query.getBytes("utf-8"), language, timestamp); + nativeRunInteractiveSearch(query.getBytes("utf-8"), language, timestamp, viewportOnly); } catch (UnsupportedEncodingException ignored) { } } @@ -123,7 +123,7 @@ public enum SearchEngine implements NativeSearchListener /** * @param bytes utf-8 formatted query bytes */ - private static native void nativeRunInteractiveSearch(byte[] bytes, String language, long timestamp); + private static native void nativeRunInteractiveSearch(byte[] bytes, String language, long timestamp, boolean viewportOnly); private static native void nativeShowResult(int index); diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 44d51b842d..eb0e4464bd 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -364,7 +364,7 @@ public class SearchFragment extends BaseMwmFragment { final String query = getQuery(); mLastQueryTimestamp = System.nanoTime(); - SearchEngine.runInteractiveSearch(query, Language.getKeyboardLocale(), mLastQueryTimestamp); + SearchEngine.runInteractiveSearch(query, Language.getKeyboardLocale(), mLastQueryTimestamp, true); SearchEngine.showAllResults(query); Utils.navigateToParent(getActivity()); @@ -406,7 +406,7 @@ public class SearchFragment extends BaseMwmFragment mLastQueryTimestamp = System.nanoTime(); // TODO @yunitsky Implement more elegant solution. if (getActivity() instanceof MwmActivity) - SearchEngine.runInteractiveSearch(getQuery(), Language.getKeyboardLocale(), mLastQueryTimestamp); + SearchEngine.runInteractiveSearch(getQuery(), Language.getKeyboardLocale(), mLastQueryTimestamp, false); else { final boolean searchStarted = SearchEngine.runSearch(getQuery(), Language.getKeyboardLocale(), mLastQueryTimestamp, true, diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm index 462b2ad648..c6279d6021 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm @@ -263,15 +263,15 @@ forRowAtIndexPath:(NSIndexPath *)indexPath - (void)updateSearchResultsOnMap { - if (!self.searchOnMap) - return; - GetFramework().UpdateSearchResults(searchResults); + if (self.searchOnMap) + GetFramework().UpdateSearchResults(searchResults); } - (void)updateSearchResultsInTable { - if (!IPAD && self.searchOnMap) + if (!IPAD && _searchOnMap) return; + self.commonSizingCell = nil; [self.tableView reloadData]; } @@ -296,11 +296,13 @@ forRowAtIndexPath:(NSIndexPath *)indexPath { if (!text) return; + if (locale) searchParams.SetInputLocale(locale.UTF8String); searchParams.m_query = text.precomposedStringWithCompatibilityMapping.UTF8String; searchParams.SetForceSearch(true); searchResults.Clear(); + [self updateSearch]; } @@ -310,10 +312,19 @@ forRowAtIndexPath:(NSIndexPath *)indexPath if (!searchParams.m_query.empty()) { self.watchLocationUpdates = YES; - if (self.searchOnMap) + if (IPAD) { f.StartInteractiveSearch(searchParams); - if (searchResults.GetCount()) + f.UpdateUserViewportChanged(); + } + else if (_searchOnMap) + { + search::SearchParams local(searchParams); + local.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY | + search::SearchParams::SEARCH_WORLD); + f.StartInteractiveSearch(local); + + if (searchResults.GetCount() > 0) f.ShowAllSearchResults(searchResults); f.UpdateUserViewportChanged(); } diff --git a/map/framework.cpp b/map/framework.cpp index 0a13bf3a83..31871d80d1 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -993,9 +993,7 @@ void Framework::UpdateUserViewportChanged() if (IsISActive()) { (void)GetCurrentPosition(m_lastSearch.m_lat, m_lastSearch.m_lon); - m_lastSearch.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY); m_lastSearch.SetForceSearch(false); - m_searchEngine->Search(m_lastSearch, GetCurrentViewport()); } } diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 740b58491c..ba8888e967 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -238,13 +238,11 @@ Result PreResult2::GenerateFinalResult(storage::CountryInfoGetter const & infoGe } } -Result PreResult2::GeneratePointResult(storage::CountryInfoGetter const & infoGetter, - CategoriesHolder const * pCat, - set const * pTypes, int8_t locale) const +Result PreResult2::GeneratePointResult(CategoriesHolder const * pCat, set const * pTypes, + int8_t locale) const { uint32_t const type = GetBestType(pTypes); - return Result(m_id, GetCenter(), m_str, GetRegionName(infoGetter, type), - ReadableFeatureType(pCat, type, locale)); + return Result(m_id, GetCenter(), m_str, ReadableFeatureType(pCat, type, locale)); } bool PreResult2::LessRank(PreResult2 const & r1, PreResult2 const & r2) diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 85a318e44a..6e076e4b6e 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -87,9 +87,8 @@ public: CategoriesHolder const * pCat, set const * pTypes, int8_t locale) const; - Result GeneratePointResult(storage::CountryInfoGetter const & infoGetter, - CategoriesHolder const * pCat, - set const * pTypes, int8_t locale) const; + Result GeneratePointResult(CategoriesHolder const * pCat, set const * pTypes, + int8_t locale) const; static bool LessRank(PreResult2 const & r1, PreResult2 const & r2); static bool LessDistance(PreResult2 const & r1, PreResult2 const & r2); diff --git a/search/result.cpp b/search/result.cpp index 38b663a16c..08fbc025a3 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -18,12 +18,10 @@ Result::Result(FeatureID const & id, m2::PointD const & pt, string const & str, Init(true /* metadataInitialized */); } -Result::Result(FeatureID const & id, m2::PointD const & pt, string const & str, - string const & region, string const & type) +Result::Result(FeatureID const & id, m2::PointD const & pt, string const & str, string const & type) : m_id(id) , m_center(pt) , m_str(str) - , m_region(region) , m_type(type) { Init(false /* metadataInitialized */); diff --git a/search/result.hpp b/search/result.hpp index c0ca12acba..f5a5f7334b 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -41,8 +41,7 @@ public: string const & type, uint32_t featureType, Metadata const & meta); /// Used for generation viewport results. - Result(FeatureID const & id, m2::PointD const & pt, string const & str, - string const & region, string const & type); + Result(FeatureID const & id, m2::PointD const & pt, string const & str, string const & type); /// @param[in] type Empty string - RESULT_LATLON, building address otherwise. Result(m2::PointD const & pt, string const & str, diff --git a/search/search_engine.cpp b/search/search_engine.cpp index c1211a8177..f87869598f 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -239,8 +239,7 @@ void Engine::SearchAsync() if (res.GetCount() > 0) EmitResults(params, res); } - - if (res.GetCount() < RESULTS_COUNT) + else { while (!m_query->IsCancelled()) { @@ -267,7 +266,7 @@ void Engine::SearchAsync() // Make additional search in whole mwm when not enough results (only for non-empty query). size_t const count = res.GetCount(); - if (!m_query->IsCancelled() && count < RESULTS_COUNT) + if (!viewportSearch && !m_query->IsCancelled() && count < RESULTS_COUNT) { try { diff --git a/search/search_query.cpp b/search/search_query.cpp index 7174104420..7445c5b245 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -787,7 +787,7 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) SortByIndexedValue(indV, CompFactory2()); // Do not process suggestions in additional search. - if (!allMWMs) + if (!allMWMs || res.GetCount() == 0) ProcessSuggestions(indV, res); #ifdef HOUSE_SEARCH_TEST @@ -837,10 +837,8 @@ void Query::SearchViewportPoints(Results & res) if (IsCancelled()) break; - Result r = indV[i]->GeneratePointResult(m_infoGetter, &m_categories, - &m_prefferedTypes, m_currentLocaleCode); - MakeResultHighlight(r); - res.AddResultNoChecks(move(r)); + res.AddResultNoChecks( + indV[i]->GeneratePointResult(&m_categories, &m_prefferedTypes, m_currentLocaleCode)); } } @@ -956,8 +954,9 @@ void Query::ProcessSuggestions(vector & vec, Results & res) const void Query::AddResultFromTrie(TTrieValue const & val, MwmSet::MwmId const & mwmID, ViewportID vID /*= DEFAULT_V*/) { - // If we are in viewport search mode, check actual "point-in-viewport" criteria. - if (m_queuesCount == 1 && !m_viewport[CURRENT_V].IsPointInside(val.m_pt)) + /// If we are in viewport search mode, check actual "point-in-viewport" criteria. + /// @todo Actually, this checks are more-like hack, but not a suitable place to do ... + if (m_queuesCount == 1 && vID == CURRENT_V && !m_viewport[CURRENT_V].IsPointInside(val.m_pt)) return; impl::PreResult1 res(FeatureID(mwmID, val.m_featureId), val.m_rank, @@ -1876,9 +1875,10 @@ void Query::SearchInMWM(Index::MwmHandle const & mwmHandle, SearchQueryParams co unique_ptr const trieRoot( trie::ReadTrie(SubReaderWrapper(searchReader.GetPtr()), trie::ValueReader(cp), trie::TEdgeValueReader())); + MwmSet::MwmId const mwmId = mwmHandle.GetId(); - FeaturesFilter filter( - (viewportId == DEFAULT_V || isWorld) ? 0 : &m_offsetsInViewport[viewportId][mwmId], *this); + FeaturesFilter filter(viewportId == DEFAULT_V || isWorld ? + 0 : &m_offsetsInViewport[viewportId][mwmId], *this); MatchFeaturesInTrie(params, *trieRoot, filter, [&](TTrieValue const & value) { AddResultFromTrie(value, mwmId, viewportId);