{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/48356264","id":48356264,"diff_hunk":"@@ -192,8 +187,138 @@ void Geocoder::PrepareRetrievalParams(size_t curToken, size_t endToken)\n   }\n }\n \n+void Geocoder::FillLocalitiesTable(MwmContext const & context)\n+{\n+  m_localities.clear();\n+\n+  auto addLocality = [&](size_t curToken, size_t endToken, uint32_t featureId)\n+  {\n+    FeatureType ft;\n+    context.m_vector.GetByIndex(featureId, ft);\n+    if (m_model.GetSearchType(ft) != SearchModel::SEARCH_TYPE_CITY)\n+      return;\n+\n+    m2::PointD const center = feature::GetCenter(ft, FeatureType::WORST_GEOMETRY);\n+    double const radiusM = ftypes::GetRadiusByPopulation(ft.GetPopulation());\n+\n+    Locality locality;\n+    locality.m_featureId = featureId;\n+    locality.m_startToken = curToken;\n+    locality.m_endToken = endToken;\n+    locality.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters(center, radiusM);\n+    m_localities[make_pair(curToken, endToken)].push_back(locality);\n+  };\n+\n+  for (size_t curToken = 0; curToken < m_numTokens; ++curToken)\n+  {\n+    for (size_t endToken = curToken + 1; endToken <= m_numTokens; ++endToken)\n+    {\n+      PrepareRetrievalParams(curToken, endToken);\n+      auto localities = Retrieval::RetrieveAddressFeatures(\n+          context.m_value, static_cast<my::Cancellable const &>(*this), m_retrievalParams);\n+      if (!localities || localities->PopCount() == 0)\n+        break;\n+      coding::CompressedBitVectorEnumerator::ForEach(*localities,\n+                                                     bind(addLocality, curToken, endToken, _1));\n+    }\n+  }\n+}\n+\n+template <typename TFn>\n+void Geocoder::ForEachCountry(vector<shared_ptr<MwmInfo>> const & infos, TFn && fn)\n+{\n+  for (auto const & info : infos)\n+  {\n+    if (info->GetType() != MwmInfo::COUNTRY)\n+      continue;\n+    auto handle = m_index.GetMwmHandleById(MwmSet::MwmId(info));\n+    if (!handle.IsAlive())\n+      continue;\n+    auto & value = *handle.GetValue<MwmValue>();\n+    if (!HasSearchIndex(value) || !HasGeometryIndex(value))\n+      continue;\n+    fn(make_unique<MwmContext>(value, handle.GetId()));\n+  }\n+}\n+\n+void Geocoder::DoGeocodingWithLocalities()\n+{\n+  ASSERT(m_context, (\"Mwm context must be initialized at this moment.\"));\n+\n+  m_usedTokens.resize(m_numTokens);\n+  fill(m_usedTokens.begin(), m_usedTokens.end(), false);\n+\n+  m2::RectD const countryBounds = m_context->m_value.GetHeader().GetBounds();\n+\n+  // Localities are ordered my (m_startToken, m_endToken) pairs.\n+  for (auto const & p : m_localities)\n+  {\n+    size_t const startToken = p.first.first;\n+    size_t const endToken = p.first.second;\n+    if (startToken == 0 && endToken == m_numTokens)\n+    {\n+      // Localities match to search query.\n+      for (auto const & locality : p.second)\n+        m_results->emplace_back(m_worldId, locality.m_featureId);\n+      continue;\n+    }\n+\n+    // Union of features from all localities and use result bit vector\n+    // as a filter for features retrieved during geocoding.\n+    unique_ptr<coding::CompressedBitVector> allFeatures;\n+    for (auto const & locality : p.second)\n+    {\n+      m2::RectD rect = countryBounds;\n+      if (!rect.Intersect(locality.m_rect))\n+        continue;\n+      auto features = Retrieval::RetrieveGeometryFeatures(\n+          m_context->m_value, static_cast<my::Cancellable const &>(*this), rect, m_params.m_scale);\n+      if (!features)","path":"search/v2/geocoder.cpp","position":274,"original_position":274,"commit_id":"0c5642dd83debcc9c1782a7644050ff915054b17","original_commit_id":"0c5642dd83debcc9c1782a7644050ff915054b17","user":{"login":"mpimenov","id":10366009,"avatar_url":"https://avatars.githubusercontent.com/u/10366009?v=3","gravatar_id":"","url":"https://api.github.com/users/mpimenov","html_url":"https://github.com/mpimenov","followers_url":"https://api.github.com/users/mpimenov/followers","following_url":"https://api.github.com/users/mpimenov/following{/other_user}","gists_url":"https://api.github.com/users/mpimenov/gists{/gist_id}","starred_url":"https://api.github.com/users/mpimenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpimenov/subscriptions","organizations_url":"https://api.github.com/users/mpimenov/orgs","repos_url":"https://api.github.com/users/mpimenov/repos","events_url":"https://api.github.com/users/mpimenov/events{/privacy}","received_events_url":"https://api.github.com/users/mpimenov/received_events","type":"User","site_admin":false},"body":"```|| features->PopCount() == 0```","created_at":"2015-12-23T16:01:21Z","updated_at":"2015-12-23T16:01:21Z","html_url":"https://github.com/mapsme/omim/pull/1122#discussion_r48356264","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/1122","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/48356264"},"html":{"href":"https://github.com/mapsme/omim/pull/1122#discussion_r48356264"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1122"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/1122","id":54476659,"html_url":"https://github.com/mapsme/omim/pull/1122","diff_url":"https://github.com/mapsme/omim/pull/1122.diff","patch_url":"https://github.com/mapsme/omim/pull/1122.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/1122","number":1122,"state":"open","locked":false,"title":"[search] Implemented search in locality.","user":{"login":"ygorshenin","id":454567,"avatar_url":"https://avatars.githubusercontent.com/u/454567?v=3","gravatar_id":"","url":"https://api.github.com/users/ygorshenin","html_url":"https://github.com/ygorshenin","followers_url":"https://api.github.com/users/ygorshenin/followers","following_url":"https://api.github.com/users/ygorshenin/following{/other_user}","gists_url":"https://api.github.com/users/ygorshenin/gists{/gist_id}","starred_url":"https://api.github.com/users/ygorshenin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ygorshenin/subscriptions","organizations_url":"https://api.github.com/users/ygorshenin/orgs","repos_url":"https://api.github.com/users/ygorshenin/repos","events_url":"https://api.github.com/users/ygorshenin/events{/privacy}","received_events_url":"https://api.github.com/users/ygorshenin/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-23T14:58:43Z","updated_at":"2015-12-23T16:01:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ffc91066d78f88bd67523463b2702f3b1241175","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/1122/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/1122/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/1122/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/0c5642dd83debcc9c1782a7644050ff915054b17","head":{"label":"ygorshenin:implement-locality-search","ref":"implement-locality-search","sha":"0c5642dd83debcc9c1782a7644050ff915054b17","user":{"login":"ygorshenin","id":454567,"avatar_url":"https://avatars.githubusercontent.com/u/454567?v=3","gravatar_id":"","url":"https://api.github.com/users/ygorshenin","html_url":"https://github.com/ygorshenin","followers_url":"https://api.github.com/users/ygorshenin/followers","following_url":"https://api.github.com/users/ygorshenin/following{/other_user}","gists_url":"https://api.github.com/users/ygorshenin/gists{/gist_id}","starred_url":"https://api.github.com/users/ygorshenin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ygorshenin/subscriptions","organizations_url":"https://api.github.com/users/ygorshenin/orgs","repos_url":"https://api.github.com/users/ygorshenin/repos","events_url":"https://api.github.com/users/ygorshenin/events{/privacy}","received_events_url":"https://api.github.com/users/ygorshenin/received_events","type":"User","site_admin":false},"repo":{"id":43427948,"name":"omim","full_name":"ygorshenin/omim","owner":{"login":"ygorshenin","id":454567,"avatar_url":"https://avatars.githubusercontent.com/u/454567?v=3","gravatar_id":"","url":"https://api.github.com/users/ygorshenin","html_url":"https://github.com/ygorshenin","followers_url":"https://api.github.com/users/ygorshenin/followers","following_url":"https://api.github.com/users/ygorshenin/following{/other_user}","gists_url":"https://api.github.com/users/ygorshenin/gists{/gist_id}","starred_url":"https://api.github.com/users/ygorshenin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ygorshenin/subscriptions","organizations_url":"https://api.github.com/users/ygorshenin/orgs","repos_url":"https://api.github.com/users/ygorshenin/repos","events_url":"https://api.github.com/users/ygorshenin/events{/privacy}","received_events_url":"https://api.github.com/users/ygorshenin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ygorshenin/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/ygorshenin/omim","forks_url":"https://api.github.com/repos/ygorshenin/omim/forks","keys_url":"https://api.github.com/repos/ygorshenin/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ygorshenin/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ygorshenin/omim/teams","hooks_url":"https://api.github.com/repos/ygorshenin/omim/hooks","issue_events_url":"https://api.github.com/repos/ygorshenin/omim/issues/events{/number}","events_url":"https://api.github.com/repos/ygorshenin/omim/events","assignees_url":"https://api.github.com/repos/ygorshenin/omim/assignees{/user}","branches_url":"https://api.github.com/repos/ygorshenin/omim/branches{/branch}","tags_url":"https://api.github.com/repos/ygorshenin/omim/tags","blobs_url":"https://api.github.com/repos/ygorshenin/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ygorshenin/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ygorshenin/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/ygorshenin/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ygorshenin/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/ygorshenin/omim/languages","stargazers_url":"https://api.github.com/repos/ygorshenin/omim/stargazers","contributors_url":"https://api.github.com/repos/ygorshenin/omim/contributors","subscribers_url":"https://api.github.com/repos/ygorshenin/omim/subscribers","subscription_url":"https://api.github.com/repos/ygorshenin/omim/subscription","commits_url":"https://api.github.com/repos/ygorshenin/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/ygorshenin/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/ygorshenin/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/ygorshenin/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/ygorshenin/omim/contents/{+path}","compare_url":"https://api.github.com/repos/ygorshenin/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ygorshenin/omim/merges","archive_url":"https://api.github.com/repos/ygorshenin/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ygorshenin/omim/downloads","issues_url":"https://api.github.com/repos/ygorshenin/omim/issues{/number}","pulls_url":"https://api.github.com/repos/ygorshenin/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/ygorshenin/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/ygorshenin/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ygorshenin/omim/labels{/name}","releases_url":"https://api.github.com/repos/ygorshenin/omim/releases{/id}","created_at":"2015-09-30T10:56:11Z","updated_at":"2015-09-30T10:58:25Z","pushed_at":"2015-12-23T14:58:11Z","git_url":"git://github.com/ygorshenin/omim.git","ssh_url":"git@github.com:ygorshenin/omim.git","clone_url":"https://github.com/ygorshenin/omim.git","svn_url":"https://github.com/ygorshenin/omim","homepage":null,"size":1929878,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:new-search","ref":"new-search","sha":"318aa068b789a26ecba20be75518feea806132ba","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","created_at":"2015-09-20T02:57:13Z","updated_at":"2015-12-23T15:59:28Z","pushed_at":"2015-12-23T15:05:57Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":2008448,"stargazers_count":1542,"watchers_count":1542,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":196,"mirror_url":null,"open_issues_count":91,"forks":196,"open_issues":91,"watchers":1542,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1122"},"html":{"href":"https://github.com/mapsme/omim/pull/1122"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/1122"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/1122/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1122/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1122/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/0c5642dd83debcc9c1782a7644050ff915054b17"}}}}