void SendStatistics(SearchParams const & params, m2::RectD const & viewport, Results const & res) { size_t const kMaxNumResultsToSend = 10; size_t const numResultsToSend = min(kMaxNumResultsToSend, res.GetCount()); string resultString = strings::to_string(numResultsToSend); for (size_t i = 0; i < numResultsToSend; ++i) resultString.append("\t" + res.GetResult(i).ToStringForStats()); string posX, posY; if (params.IsValidPosition()) { posX = strings::to_string(MercatorBounds::LonToX(params.m_lon)); posY = strings::to_string(MercatorBounds::LatToY(params.m_lat)); } alohalytics::TStringMap const stats = { {"posX", posX}, {"posY", posY}, {"viewportMinX", strings::to_string(viewport.minX())}, {"viewportMinY", strings::to_string(viewport.minY())}, {"viewportMaxX", strings::to_string(viewport.maxX())}, {"viewportMaxY", strings::to_string(viewport.maxY())}, {"query", params.m_query}, {"locale", params.m_inputLocale}, {"results", resultString}, }; alohalytics::LogEvent("searchEmitResultsAndCoords", stats); }
void Engine::SetRankPivot(SearchParams const & params, m2::RectD const & viewport, bool viewportSearch, Query & processor) { if (!viewportSearch && params.IsValidPosition()) { m2::PointD const pos = MercatorBounds::FromLatLon(params.m_lat, params.m_lon); if (m2::Inflate(viewport, viewport.SizeX() / 4.0, viewport.SizeY() / 4.0).IsPointInside(pos)) { processor.SetRankPivot(pos); return; } } processor.SetRankPivot(viewport.Center()); }
void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport, shared_ptr<QueryHandle> handle, Query & processor) { bool const viewportSearch = params.GetMode() == Mode::Viewport; // Initialize query processor. processor.Init(viewportSearch); handle->Attach(processor); MY_SCOPE_GUARD(detach, [&handle] { handle->Detach(); }); // Early exit when query processing is cancelled. if (processor.IsCancelled()) { params.m_onResults(Results::GetEndMarker(true /* isCancelled */)); return; } SetRankPivot(params, viewport, viewportSearch, processor); if (params.IsValidPosition()) processor.SetPosition(MercatorBounds::FromLatLon(params.m_lat, params.m_lon)); else processor.SetPosition(viewport.Center()); processor.SetMode(params.GetMode()); processor.SetSuggestsEnabled(params.GetSuggestsEnabled()); // This flag is needed for consistency with old search algorithm // only. It will be gone when we remove old search code. processor.SetSearchInWorld(true); processor.SetInputLocale(params.m_inputLocale); ASSERT(!params.m_query.empty(), ()); processor.SetQuery(params.m_query); Results res; processor.SearchCoordinates(res); try { if (params.m_onStarted) params.m_onStarted(); processor.SetViewport(viewport, true /* forceUpdate */); if (viewportSearch) processor.SearchViewportPoints(res); else processor.Search(res, kResultsCount); if (!processor.IsCancelled()) EmitResults(params, res); } catch (Query::CancelException const &) { LOG(LDEBUG, ("Search has been cancelled.")); } if (!viewportSearch && !processor.IsCancelled()) SendStatistics(params, viewport, res); // Emit finish marker to client. params.m_onResults(Results::GetEndMarker(processor.IsCancelled())); }