diff --git a/search/search_quality/search_quality_tool/search_quality_tool.cpp b/search/search_quality/search_quality_tool/search_quality_tool.cpp index ab25d62a0d..d2493452a8 100644 --- a/search/search_quality/search_quality_tool/search_quality_tool.cpp +++ b/search/search_quality/search_quality_tool/search_quality_tool.cpp @@ -443,13 +443,17 @@ int main(int argc, char * argv[]) } ofstream csv; + bool dumpCSV = false; if (!FLAGS_ranking_csv_file.empty()) { - ofstream os(FLAGS_ranking_csv_file); - csv.swap(os); + csv.open(FLAGS_ranking_csv_file); + if (!csv.is_open()) + LOG(LERROR, ("Can't open file for CSV dump:", FLAGS_ranking_csv_file)); + else + dumpCSV = true; } - if (csv.is_open()) + if (dumpCSV) { search::v2::RankingInfo::PrintCSVHeader(csv); csv << endl; @@ -464,7 +468,7 @@ int main(int argc, char * argv[]) PrintTopResults(MakePrefixFree(queries[i]), requests[i]->Results(), FLAGS_top, responseTimes[i]); - if (csv.is_open()) + if (dumpCSV) { for (auto const & result : requests[i]->Results()) { diff --git a/search/search_query.cpp b/search/search_query.cpp index 61a366947a..b11a22ee2e 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -653,7 +653,7 @@ class PreResult2Maker info.m_rank = preInfo.m_rank; - info.m_searchType = v2::SearchModel::Instance().GetSearchType(ft); + info.m_searchType = preInfo.m_searchType; info.m_nameScore = v2::NAME_SCORE_ZERO; for (auto const & lang : m_params.m_langs) diff --git a/search/v2/geocoder.cpp b/search/v2/geocoder.cpp index efe7f7fbeb..3866d48c66 100644 --- a/search/v2/geocoder.cpp +++ b/search/v2/geocoder.cpp @@ -721,7 +721,7 @@ void Geocoder::FillLocalitiesTable() if (numCities < kMaxNumCities && ft.GetFeatureType() == feature::GEOM_POINT) { ++numCities; - City city = l; + City city(l, SearchModel::SEARCH_TYPE_CITY); city.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters( feature::GetCenter(ft), ftypes::GetRadiusByPopulation(ft.GetPopulation())); @@ -808,7 +808,7 @@ void Geocoder::FillVillageLocalities() continue; ++numVillages; - City village = l; + City village(l, SearchModel::SEARCH_TYPE_VILLAGE); village.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters( feature::GetCenter(ft), ftypes::GetRadiusByPopulation(ft.GetPopulation())); @@ -902,7 +902,7 @@ void Geocoder::MatchRegions(RegionType type) if (AllTokensUsed()) { // Region matches to search query, we need to emit it as is. - EmitResult(m_worldId, region.m_featureId, startToken, endToken); + EmitResult(region, startToken, endToken); continue; } @@ -947,8 +947,8 @@ void Geocoder::MatchCities() ScopedMarkTokens mark(m_usedTokens, startToken, endToken); if (AllTokensUsed()) { - // City matches to search query. - EmitResult(city.m_countryId, city.m_featureId, startToken, endToken); + // City matches to search query, we need to emit it as is. + EmitResult(city, startToken, endToken); continue; } @@ -1243,25 +1243,26 @@ void Geocoder::FindPaths() sortedLayers.push_back(&layer); sort(sortedLayers.begin(), sortedLayers.end(), my::CompareBy(&FeaturesLayer::m_type)); - auto startToken = sortedLayers.front()->m_startToken; - auto endToken = sortedLayers.front()->m_endToken; + auto const & innermostLayer = *sortedLayers.front(); m_finder.ForEachReachableVertex(*m_matcher, sortedLayers, - [this, startToken, endToken](IntersectionResult const & result) - { + [this, &innermostLayer](IntersectionResult const & result) + { ASSERT(result.IsValid(), ()); // TODO(@y, @m, @vng): use rest fields of IntersectionResult for // better scoring. - EmitResult(m_context->GetId(), result.InnermostResult(), startToken, endToken); + EmitResult(m_context->GetId(), result.InnermostResult(), innermostLayer.m_type, + innermostLayer.m_startToken, innermostLayer.m_endToken); }); } -void Geocoder::EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, size_t startToken, - size_t endToken) +void Geocoder::EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, SearchModel::SearchType type, + size_t startToken, size_t endToken) { FeatureID id(mwmId, ftId); PreRankingInfo info; + info.m_searchType = type; info.m_startToken = startToken; info.m_endToken = endToken; if (auto const & mwmInfo = mwmId.GetInfo()) @@ -1276,6 +1277,23 @@ void Geocoder::EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, size_t sta m_results->emplace_back(move(id), move(info)); } +void Geocoder::EmitResult(Region const & region, size_t startToken, size_t endToken) +{ + SearchModel::SearchType type; + switch (region.m_type) + { + case REGION_TYPE_STATE: type = SearchModel::SEARCH_TYPE_STATE; break; + case REGION_TYPE_COUNTRY: type = SearchModel::SEARCH_TYPE_COUNTRY; break; + case REGION_TYPE_COUNT: type = SearchModel::SEARCH_TYPE_COUNT; break; + } + EmitResult(m_worldId, region.m_featureId, type, startToken, endToken); +} + +void Geocoder::EmitResult(City const & city, size_t startToken, size_t endToken) +{ + EmitResult(city.m_countryId, city.m_featureId, city.m_type, startToken, endToken); +} + void Geocoder::FillResultRanks() { sort(m_results->begin(), m_results->end(), my::CompareBy(&TResult::first)); @@ -1339,8 +1357,9 @@ void Geocoder::MatchUnclassified(size_t curToken) auto emitUnclassified = [&](uint32_t featureId) { - if (GetSearchTypeInGeocoding(featureId) == SearchModel::SEARCH_TYPE_UNCLASSIFIED) - EmitResult(m_context->GetId(), featureId, startToken, curToken); + auto type = GetSearchTypeInGeocoding(featureId); + if (type == SearchModel::SEARCH_TYPE_UNCLASSIFIED) + EmitResult(m_context->GetId(), featureId, type, startToken, curToken); }; coding::CompressedBitVectorEnumerator::ForEach(*allFeatures, emitUnclassified); } diff --git a/search/v2/geocoder.hpp b/search/v2/geocoder.hpp index 8772d27439..875c4313fd 100644 --- a/search/v2/geocoder.hpp +++ b/search/v2/geocoder.hpp @@ -122,9 +122,10 @@ public: // states and Locality for smaller settlements. struct City : public Locality { - City(Locality const & l): Locality(l) {} + City(Locality const & l, SearchModel::SearchType type) : Locality(l), m_type(type) {} m2::RectD m_rect; + SearchModel::SearchType m_type; }; using TResult = pair; @@ -223,7 +224,10 @@ private: void FindPaths(); // Forms result and appends it to |m_results|. - void EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, size_t startToken, size_t endToken); + void EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, SearchModel::SearchType type, + size_t startToken, size_t endToken); + void EmitResult(Region const & region, size_t startToken, size_t endToken); + void EmitResult(City const & city, size_t startToken, size_t endToken); // Computes rank for all results in |m_results|. void FillResultRanks(); diff --git a/search/v2/pre_ranking_info.hpp b/search/v2/pre_ranking_info.hpp index d9443cda2f..cbd13cb680 100644 --- a/search/v2/pre_ranking_info.hpp +++ b/search/v2/pre_ranking_info.hpp @@ -1,5 +1,7 @@ #pragma once +#include "search/v2/search_model.hpp" + #include "std/cstdint.hpp" namespace search @@ -23,6 +25,9 @@ struct PreRankingInfo // Rank of the feature. uint8_t m_rank = 0; + + // Search type for the feature. + SearchModel::SearchType m_searchType = SearchModel::SEARCH_TYPE_COUNT; }; } // namespace v2 } // namespace search