[search] SearchModel -> Model.

This commit is contained in:
Yuri Gorshenin 2017-08-14 17:23:13 +03:00 committed by mpimenov
parent 9c46e207c6
commit 0444d83d8f
18 changed files with 154 additions and 161 deletions

View file

@ -13,7 +13,7 @@ void FeaturesLayer::Clear()
m_sortedFeatures = nullptr;
m_subQuery.clear();
m_tokenRange.Clear();
m_type = SearchModel::SEARCH_TYPE_COUNT;
m_type = Model::TYPE_COUNT;
m_hasDelayedFeatures = false;
m_lastTokenIsPrefix = false;
}

View file

@ -24,7 +24,7 @@ struct FeaturesLayer
strings::UniString m_subQuery;
TokenRange m_tokenRange;
SearchModel::SearchType m_type;
Model::Type m_type;
// *NOTE* This field is meaningful only when m_type equals to
// SEARCH_TYPE_BUILDING.

View file

@ -70,24 +70,23 @@ public:
return;
switch (parent.m_type)
{
case SearchModel::SEARCH_TYPE_POI:
case SearchModel::SEARCH_TYPE_CITY:
case SearchModel::SEARCH_TYPE_VILLAGE:
case SearchModel::SEARCH_TYPE_STATE:
case SearchModel::SEARCH_TYPE_COUNTRY:
case SearchModel::SEARCH_TYPE_UNCLASSIFIED:
case SearchModel::SEARCH_TYPE_COUNT:
case Model::TYPE_POI:
case Model::TYPE_CITY:
case Model::TYPE_VILLAGE:
case Model::TYPE_STATE:
case Model::TYPE_COUNTRY:
case Model::TYPE_UNCLASSIFIED:
case Model::TYPE_COUNT:
ASSERT(false, ("Invalid parent layer type:", parent.m_type));
break;
case SearchModel::SEARCH_TYPE_BUILDING:
ASSERT_EQUAL(child.m_type, SearchModel::SEARCH_TYPE_POI, ());
case Model::TYPE_BUILDING:
ASSERT_EQUAL(child.m_type, Model::TYPE_POI, ());
MatchPOIsWithBuildings(child, parent, forward<TFn>(fn));
break;
case SearchModel::SEARCH_TYPE_STREET:
ASSERT(child.m_type == SearchModel::SEARCH_TYPE_POI ||
child.m_type == SearchModel::SEARCH_TYPE_BUILDING,
case Model::TYPE_STREET:
ASSERT(child.m_type == Model::TYPE_POI || child.m_type == Model::TYPE_BUILDING,
("Invalid child layer type:", child.m_type));
if (child.m_type == SearchModel::SEARCH_TYPE_POI)
if (child.m_type == Model::TYPE_POI)
MatchPOIsWithStreets(child, parent, forward<TFn>(fn));
else
MatchBuildingsWithStreets(child, parent, forward<TFn>(fn));
@ -105,8 +104,8 @@ private:
// each building, tries to find all POIs located at distance less
// than kBuildingRadiusMeters.
ASSERT_EQUAL(child.m_type, SearchModel::SEARCH_TYPE_POI, ());
ASSERT_EQUAL(parent.m_type, SearchModel::SEARCH_TYPE_BUILDING, ());
ASSERT_EQUAL(child.m_type, Model::TYPE_POI, ());
ASSERT_EQUAL(parent.m_type, Model::TYPE_BUILDING, ());
auto const & pois = *child.m_sortedFeatures;
auto const & buildings = *parent.m_sortedFeatures;
@ -182,8 +181,8 @@ private:
template <typename TFn>
void MatchPOIsWithStreets(FeaturesLayer const & child, FeaturesLayer const & parent, TFn && fn)
{
ASSERT_EQUAL(child.m_type, SearchModel::SEARCH_TYPE_POI, ());
ASSERT_EQUAL(parent.m_type, SearchModel::SEARCH_TYPE_STREET, ());
ASSERT_EQUAL(child.m_type, Model::TYPE_POI, ());
ASSERT_EQUAL(parent.m_type, Model::TYPE_STREET, ());
auto const & pois = *child.m_sortedFeatures;
auto const & streets = *parent.m_sortedFeatures;
@ -218,8 +217,8 @@ private:
void MatchBuildingsWithStreets(FeaturesLayer const & child, FeaturesLayer const & parent,
TFn && fn)
{
ASSERT_EQUAL(child.m_type, SearchModel::SEARCH_TYPE_BUILDING, ());
ASSERT_EQUAL(parent.m_type, SearchModel::SEARCH_TYPE_STREET, ());
ASSERT_EQUAL(child.m_type, Model::TYPE_BUILDING, ());
ASSERT_EQUAL(parent.m_type, Model::TYPE_STREET, ());
auto const & buildings = *child.m_sortedFeatures;
auto const & streets = *parent.m_sortedFeatures;

View file

@ -116,7 +116,7 @@ void FeaturesLayerPathFinder::FindReachableVerticesTopDown(
FeaturesLayer child(*layers[i - 1]);
child.m_hasDelayedFeatures =
child.m_type == SearchModel::SEARCH_TYPE_BUILDING &&
child.m_type == Model::TYPE_BUILDING &&
house_numbers::LooksLikeHouseNumber(child.m_subQuery, child.m_lastTokenIsPrefix);
buffer.clear();
@ -164,7 +164,7 @@ void FeaturesLayerPathFinder::FindReachableVerticesBottomUp(
FeaturesLayer parent(*layers[i + 1]);
parent.m_hasDelayedFeatures =
parent.m_type == SearchModel::SEARCH_TYPE_BUILDING &&
parent.m_type == Model::TYPE_BUILDING &&
house_numbers::LooksLikeHouseNumber(parent.m_subQuery, parent.m_lastTokenIsPrefix);
buffer.clear();

View file

@ -549,8 +549,7 @@ void Geocoder::InitBaseContext(BaseContext & ctx)
ctx.m_hotelsFilter = m_hotelsFilter.MakeScopedFilter(*m_context, m_params.m_hotelsFilter);
}
void Geocoder::InitLayer(SearchModel::SearchType type, TokenRange const & tokenRange,
FeaturesLayer & layer)
void Geocoder::InitLayer(Model::Type type, TokenRange const & tokenRange, FeaturesLayer & layer)
{
layer.Clear();
layer.m_type = type;
@ -613,9 +612,9 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx)
}
};
switch (m_model.GetSearchType(ft))
switch (m_model.GetType(ft))
{
case SearchModel::SEARCH_TYPE_CITY:
case Model::TYPE_CITY:
{
if (numCities < kMaxNumCities && ft.GetFeatureType() == feature::GEOM_POINT)
{
@ -625,7 +624,7 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx)
auto const population = ftypes::GetPopulation(ft);
auto const radius = ftypes::GetRadiusByPopulation(population);
City city(l, SearchModel::SEARCH_TYPE_CITY);
City city(l, Model::TYPE_CITY);
city.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters(center, radius);
#if defined(DEBUG)
@ -637,12 +636,12 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx)
}
break;
}
case SearchModel::SEARCH_TYPE_STATE:
case Model::TYPE_STATE:
{
addRegionMaps(kMaxNumStates, Region::TYPE_STATE, numStates);
break;
}
case SearchModel::SEARCH_TYPE_COUNTRY:
case Model::TYPE_COUNTRY:
{
addRegionMaps(kMaxNumCountries, Region::TYPE_COUNTRY, numCountries);
break;
@ -665,13 +664,13 @@ void Geocoder::FillVillageLocalities(BaseContext const & ctx)
if (!m_context->GetFeature(l.m_featureId, ft))
continue;
if (m_model.GetSearchType(ft) != SearchModel::SEARCH_TYPE_VILLAGE)
if (m_model.GetType(ft) != Model::TYPE_VILLAGE)
continue;
// We accept lines and areas as village features.
auto const center = feature::GetCenter(ft);
++numVillages;
City village(l, SearchModel::SEARCH_TYPE_VILLAGE);
City village(l, Model::TYPE_VILLAGE);
auto const population = ftypes::GetPopulation(ft);
auto const radius = ftypes::GetRadiusByPopulation(population);
@ -917,7 +916,7 @@ void Geocoder::CreateStreetsLayerAndMatchLowerLayers(BaseContext & ctx,
MY_SCOPE_GUARD(cleanupGuard, bind(&vector<FeaturesLayer>::pop_back, &layers));
auto & layer = layers.back();
InitLayer(SearchModel::SEARCH_TYPE_STREET, prediction.m_tokenRange, layer);
InitLayer(Model::TYPE_STREET, prediction.m_tokenRange, layer);
vector<uint32_t> sortedFeatures;
sortedFeatures.reserve(prediction.m_features.PopCount());
@ -953,17 +952,17 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
filtered = m_filter->Filter(m_postcodes.m_features);
filtered.ForEach([&](uint64_t bit) {
auto const featureId = base::asserted_cast<uint32_t>(bit);
SearchModel::SearchType searchType;
if (GetSearchTypeInGeocoding(ctx, featureId, searchType))
Model::Type type;
if (GetTypeInGeocoding(ctx, featureId, type))
{
EmitResult(ctx, m_context->GetId(), featureId, searchType, m_postcodes.m_tokenRange,
EmitResult(ctx, m_context->GetId(), featureId, type, m_postcodes.m_tokenRange,
nullptr /* geoParts */);
}
});
return;
}
if (!(layers.size() == 1 && layers[0].m_type == SearchModel::SEARCH_TYPE_STREET))
if (!(layers.size() == 1 && layers[0].m_type == Model::TYPE_STREET))
return FindPaths(ctx);
// If there're only one street layer but user also entered a
@ -978,8 +977,8 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
{
if (!m_postcodes.m_features.HasBit(id))
continue;
EmitResult(ctx, m_context->GetId(), id, SearchModel::SEARCH_TYPE_STREET,
layers.back().m_tokenRange, nullptr /* geoParts */);
EmitResult(ctx, m_context->GetId(), id, Model::TYPE_STREET, layers.back().m_tokenRange,
nullptr /* geoParts */);
}
}
@ -989,7 +988,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
MY_SCOPE_GUARD(cleanupGuard, bind(&vector<FeaturesLayer>::pop_back, &layers));
auto & layer = layers.back();
InitLayer(SearchModel::SEARCH_TYPE_BUILDING, m_postcodes.m_tokenRange, layer);
InitLayer(Model::TYPE_BUILDING, m_postcodes.m_tokenRange, layer);
vector<uint32_t> features;
m_postcodes.m_features.ForEach([&features](uint64_t bit) {
@ -1004,7 +1003,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
// Clusters of features by search type. Each cluster is a sorted
// list of ids.
size_t const kNumClusters = SearchModel::SEARCH_TYPE_BUILDING + 1;
size_t const kNumClusters = Model::TYPE_BUILDING + 1;
vector<uint32_t> clusters[kNumClusters];
// Appends |featureId| to the end of the corresponding cluster, if
@ -1012,17 +1011,16 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
auto clusterize = [&](uint64_t bit)
{
auto const featureId = base::asserted_cast<uint32_t>(bit);
SearchModel::SearchType searchType;
if (!GetSearchTypeInGeocoding(ctx, featureId, searchType))
Model::Type type;
if (!GetTypeInGeocoding(ctx, featureId, type))
return;
// All SEARCH_TYPE_CITY features were filtered in
// MatchCities(). All SEARCH_TYPE_STREET features were
// filtered in GreedilyMatchStreets().
if (searchType < kNumClusters)
// All TYPE_CITY features were filtered in MatchCities(). All
// TYPE_STREET features were filtered in GreedilyMatchStreets().
if (type < kNumClusters)
{
if (m_postcodes.m_features.IsEmpty() || m_postcodes.m_features.HasBit(featureId))
clusters[searchType].push_back(featureId);
clusters[type].push_back(featureId);
}
};
@ -1099,7 +1097,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
auto & layer = layers.back();
layer.m_sortedFeatures = &clusters[i];
if (i == SearchModel::SEARCH_TYPE_BUILDING)
if (i == Model::TYPE_BUILDING)
{
if (layer.m_sortedFeatures->empty() && !looksLikeHouseNumber)
continue;
@ -1109,7 +1107,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
continue;
}
layer.m_type = static_cast<SearchModel::SearchType>(i);
layer.m_type = static_cast<Model::Type>(i);
if (IsLayerSequenceSane(layers))
MatchPOIsAndBuildings(ctx, curToken + n);
}
@ -1119,8 +1117,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
bool Geocoder::IsLayerSequenceSane(vector<FeaturesLayer> const & layers) const
{
ASSERT(!layers.empty(), ());
static_assert(SearchModel::SEARCH_TYPE_COUNT <= 32,
"Select a wider type to represent search types mask.");
static_assert(Model::TYPE_COUNT <= 32, "Select a wider type to represent search types mask.");
uint32_t mask = 0;
size_t buildingIndex = layers.size();
size_t streetIndex = layers.size();
@ -1130,7 +1127,7 @@ bool Geocoder::IsLayerSequenceSane(vector<FeaturesLayer> const & layers) const
for (size_t i = 0; i < layers.size(); ++i)
{
auto const & layer = layers[i];
ASSERT_NOT_EQUAL(layer.m_type, SearchModel::SEARCH_TYPE_COUNT, ());
ASSERT_NOT_EQUAL(layer.m_type, Model::TYPE_COUNT, ());
// TODO (@y): probably it's worth to check belongs-to-locality here.
uint32_t bit = 1U << layer.m_type;
@ -1138,9 +1135,9 @@ bool Geocoder::IsLayerSequenceSane(vector<FeaturesLayer> const & layers) const
return false;
mask |= bit;
if (layer.m_type == SearchModel::SEARCH_TYPE_BUILDING)
if (layer.m_type == Model::TYPE_BUILDING)
buildingIndex = i;
else if (layer.m_type == SearchModel::SEARCH_TYPE_STREET)
else if (layer.m_type == Model::TYPE_STREET)
streetIndex = i;
}
@ -1189,7 +1186,7 @@ void Geocoder::FindPaths(BaseContext const & ctx)
}
void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId, uint32_t ftId,
SearchModel::SearchType type, TokenRange const & tokenRange,
Model::Type type, TokenRange const & tokenRange,
IntersectionResult const * geoParts)
{
FeatureID id(mwmId, ftId);
@ -1197,7 +1194,7 @@ void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId,
if (ctx.m_hotelsFilter && !ctx.m_hotelsFilter->Matches(id))
return;
if (m_params.m_cianMode && type != SearchModel::SEARCH_TYPE_BUILDING)
if (m_params.m_cianMode && type != Model::TYPE_BUILDING)
return;
// Distance and rank will be filled at the end, for all results at once.
@ -1211,13 +1208,13 @@ void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId,
for (auto const * region : ctx.m_regions)
{
auto const regionType = Region::ToSearchType(region->m_type);
ASSERT_NOT_EQUAL(regionType, SearchModel::SEARCH_TYPE_COUNT, ());
auto const regionType = Region::ToModelType(region->m_type);
ASSERT_NOT_EQUAL(regionType, Model::TYPE_COUNT, ());
info.m_tokenRange[regionType] = region->m_tokenRange;
}
if (ctx.m_city)
info.m_tokenRange[SearchModel::SEARCH_TYPE_CITY] = ctx.m_city->m_tokenRange;
info.m_tokenRange[Model::TYPE_CITY] = ctx.m_city->m_tokenRange;
if (geoParts)
info.m_geoParts = *geoParts;
@ -1228,7 +1225,7 @@ void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId,
void Geocoder::EmitResult(BaseContext const & ctx, Region const & region,
TokenRange const & tokenRange)
{
auto const type = Region::ToSearchType(region.m_type);
auto const type = Region::ToModelType(region.m_type);
EmitResult(ctx, region.m_countryId, region.m_featureId, type, tokenRange, nullptr /* geoParts */);
}
@ -1268,12 +1265,12 @@ void Geocoder::MatchUnclassified(BaseContext & ctx, size_t curToken)
auto emitUnclassified = [&](uint64_t bit)
{
auto const featureId = base::asserted_cast<uint32_t>(bit);
SearchModel::SearchType searchType;
if (!GetSearchTypeInGeocoding(ctx, featureId, searchType))
Model::Type type;
if (!GetTypeInGeocoding(ctx, featureId, type))
return;
if (searchType == SearchModel::SEARCH_TYPE_UNCLASSIFIED)
if (type == Model::TYPE_UNCLASSIFIED)
{
EmitResult(ctx, m_context->GetId(), featureId, searchType, TokenRange(startToken, curToken),
EmitResult(ctx, m_context->GetId(), featureId, type, TokenRange(startToken, curToken),
nullptr /* geoParts */);
}
};
@ -1296,24 +1293,23 @@ CBV Geocoder::RetrieveGeometryFeatures(MwmContext const & context, m2::RectD con
}
}
bool Geocoder::GetSearchTypeInGeocoding(BaseContext const & ctx, uint32_t featureId,
SearchModel::SearchType & searchType)
bool Geocoder::GetTypeInGeocoding(BaseContext const & ctx, uint32_t featureId, Model::Type & type)
{
if (ctx.m_streets.HasBit(featureId))
{
searchType = SearchModel::SEARCH_TYPE_STREET;
type = Model::TYPE_STREET;
return true;
}
if (ctx.m_villages.HasBit(featureId))
{
searchType = SearchModel::SEARCH_TYPE_VILLAGE;
type = Model::TYPE_VILLAGE;
return true;
}
FeatureType feature;
if (m_context->GetFeature(featureId, feature))
{
searchType = m_model.GetSearchType(feature);
type = m_model.GetType(feature);
return true;
}

View file

@ -133,8 +133,7 @@ private:
// for each token and saves it to m_addressFeatures.
void InitBaseContext(BaseContext & ctx);
void InitLayer(SearchModel::SearchType type, TokenRange const & tokenRange,
FeaturesLayer & layer);
void InitLayer(Model::Type type, TokenRange const & tokenRange, FeaturesLayer & layer);
void FillLocalityCandidates(BaseContext const & ctx,
CBV const & filter, size_t const maxNumLocalities,
@ -195,7 +194,7 @@ private:
// Forms result and feeds it to |m_preRanker|.
void EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId, uint32_t ftId,
SearchModel::SearchType type, TokenRange const & tokenRange,
Model::Type type, TokenRange const & tokenRange,
IntersectionResult const * geoParts);
void EmitResult(BaseContext const & ctx, Region const & region, TokenRange const & tokenRange);
void EmitResult(BaseContext const & ctx, City const & city, TokenRange const & tokenRange);
@ -213,8 +212,8 @@ private:
// This is a faster wrapper around SearchModel::GetSearchType(), as
// it uses pre-loaded lists of streets and villages.
WARN_UNUSED_RESULT bool GetSearchTypeInGeocoding(BaseContext const & ctx, uint32_t featureId,
SearchModel::SearchType & searchType);
WARN_UNUSED_RESULT bool GetTypeInGeocoding(BaseContext const & ctx, uint32_t featureId,
Model::Type & type);
Index const & m_index;
@ -232,7 +231,7 @@ private:
// This field is used to map features to a limited number of search
// classes.
SearchModel m_model;
Model m_model;
// Following fields are set up by Search() method and can be
// modified and used only from Search() or its callees.

View file

@ -5,13 +5,13 @@
namespace search
{
// static
SearchModel::SearchType Region::ToSearchType(Type type)
Model::Type Region::ToModelType(Type type)
{
switch (type)
{
case Region::TYPE_STATE: return SearchModel::SEARCH_TYPE_STATE;
case Region::TYPE_COUNTRY: return SearchModel::SEARCH_TYPE_COUNTRY;
case Region::TYPE_COUNT: return SearchModel::SEARCH_TYPE_COUNT;
case Region::TYPE_STATE: return Model::TYPE_STATE;
case Region::TYPE_COUNTRY: return Model::TYPE_COUNTRY;
case Region::TYPE_COUNT: return Model::TYPE_COUNT;
}
}

View file

@ -48,7 +48,7 @@ struct Region : public Locality
Region(Locality const & locality, Type type) : Locality(locality), m_center(0, 0), m_type(type) {}
static SearchModel::SearchType ToSearchType(Type type);
static Model::Type ToModelType(Type type);
storage::CountryInfoGetter::TRegionIdSet m_ids;
std::string m_defaultName;
@ -63,12 +63,12 @@ struct Region : public Locality
// states and Locality for smaller settlements.
struct City : public Locality
{
City(Locality const & locality, SearchModel::SearchType type) : Locality(locality), m_type(type)
City(Locality const & locality, Model::Type type) : Locality(locality), m_type(type)
{
}
m2::RectD m_rect;
SearchModel::SearchType m_type;
Model::Type m_type;
#if defined(DEBUG)
std::string m_defaultName;

View file

@ -7,19 +7,19 @@ namespace search
// static
uint32_t const IntersectionResult::kInvalidId;
void IntersectionResult::Set(SearchModel::SearchType type, uint32_t id)
void IntersectionResult::Set(Model::Type type, uint32_t id)
{
switch (type)
{
case SearchModel::SEARCH_TYPE_POI: m_poi = id; break;
case SearchModel::SEARCH_TYPE_BUILDING: m_building = id; break;
case SearchModel::SEARCH_TYPE_STREET: m_street = id; break;
case SearchModel::SEARCH_TYPE_CITY:
case SearchModel::SEARCH_TYPE_VILLAGE:
case SearchModel::SEARCH_TYPE_STATE:
case SearchModel::SEARCH_TYPE_COUNTRY:
case SearchModel::SEARCH_TYPE_UNCLASSIFIED:
case SearchModel::SEARCH_TYPE_COUNT: ASSERT(false, ("Unsupported type.")); break;
case Model::TYPE_POI: m_poi = id; break;
case Model::TYPE_BUILDING: m_building = id; break;
case Model::TYPE_STREET: m_street = id; break;
case Model::TYPE_CITY:
case Model::TYPE_VILLAGE:
case Model::TYPE_STATE:
case Model::TYPE_COUNTRY:
case Model::TYPE_UNCLASSIFIED:
case Model::TYPE_COUNT: ASSERT(false, ("Unsupported type.")); break;
}
}

View file

@ -14,7 +14,7 @@ struct IntersectionResult
{
static uint32_t constexpr kInvalidId = std::numeric_limits<uint32_t>::max();
void Set(SearchModel::SearchType type, uint32_t id);
void Set(Model::Type type, uint32_t id);
// Returns the first valid feature among the [POI, BUILDING,
// STREET].

View file

@ -99,7 +99,7 @@ private:
};
} // namespace
SearchModel::SearchType SearchModel::GetSearchType(FeatureType const & feature) const
Model::Type Model::GetType(FeatureType const & feature) const
{
static auto const & buildingChecker = CustomIsBuildingChecker::Instance();
static auto const & cianChecker = IsCianChecker::Instance();
@ -108,48 +108,48 @@ SearchModel::SearchType SearchModel::GetSearchType(FeatureType const & feature)
static auto const & poiChecker = IsPoiChecker::Instance();
if (m_cianEnabled && cianChecker(feature))
return SEARCH_TYPE_BUILDING;
return TYPE_BUILDING;
if (!m_cianEnabled && buildingChecker(feature))
return SEARCH_TYPE_BUILDING;
return TYPE_BUILDING;
if (streetChecker(feature))
return SEARCH_TYPE_STREET;
return TYPE_STREET;
if (localityChecker(feature))
{
Type type = localityChecker.GetType(feature);
auto const type = localityChecker.GetType(feature);
switch (type)
{
case NONE: ASSERT(false, ("Unknown locality.")); return SEARCH_TYPE_UNCLASSIFIED;
case STATE: return SEARCH_TYPE_STATE;
case COUNTRY: return SEARCH_TYPE_COUNTRY;
case NONE: ASSERT(false, ("Unknown locality.")); return TYPE_UNCLASSIFIED;
case STATE: return TYPE_STATE;
case COUNTRY: return TYPE_COUNTRY;
case CITY:
case TOWN: return SEARCH_TYPE_CITY;
case VILLAGE: return SEARCH_TYPE_VILLAGE;
case LOCALITY_COUNT: return SEARCH_TYPE_UNCLASSIFIED;
case TOWN: return TYPE_CITY;
case VILLAGE: return TYPE_VILLAGE;
case LOCALITY_COUNT: return TYPE_UNCLASSIFIED;
}
}
if (poiChecker(feature))
return SEARCH_TYPE_POI;
return TYPE_POI;
return SEARCH_TYPE_UNCLASSIFIED;
return TYPE_UNCLASSIFIED;
}
string DebugPrint(SearchModel::SearchType type)
string DebugPrint(Model::Type type)
{
switch (type)
{
case SearchModel::SEARCH_TYPE_POI: return "POI";
case SearchModel::SEARCH_TYPE_BUILDING: return "Building";
case SearchModel::SEARCH_TYPE_STREET: return "Street";
case SearchModel::SEARCH_TYPE_CITY: return "City";
case SearchModel::SEARCH_TYPE_VILLAGE: return "Village";
case SearchModel::SEARCH_TYPE_STATE: return "State";
case SearchModel::SEARCH_TYPE_COUNTRY: return "Country";
case SearchModel::SEARCH_TYPE_UNCLASSIFIED: return "Unclassified";
case SearchModel::SEARCH_TYPE_COUNT: return "Count";
case Model::TYPE_POI: return "POI";
case Model::TYPE_BUILDING: return "Building";
case Model::TYPE_STREET: return "Street";
case Model::TYPE_CITY: return "City";
case Model::TYPE_VILLAGE: return "Village";
case Model::TYPE_STATE: return "State";
case Model::TYPE_COUNTRY: return "Country";
case Model::TYPE_UNCLASSIFIED: return "Unclassified";
case Model::TYPE_COUNT: return "Count";
}
ASSERT(false, ("Unknown search type:", static_cast<int>(type)));
return string();

View file

@ -22,32 +22,32 @@ public:
// This class is used to map feature types to a restricted set of
// different search classes (do not confuse these classes with search
// categories - they are completely different things).
class SearchModel
class Model
{
public:
enum SearchType
enum Type
{
// Low-level features such as amenities, offices, shops, buildings
// without house number, etc.
SEARCH_TYPE_POI,
TYPE_POI,
// All features with set house number.
SEARCH_TYPE_BUILDING,
TYPE_BUILDING,
SEARCH_TYPE_STREET,
TYPE_STREET,
// All low-level features except POI, BUILDING and STREET.
SEARCH_TYPE_UNCLASSIFIED,
TYPE_UNCLASSIFIED,
SEARCH_TYPE_VILLAGE,
SEARCH_TYPE_CITY,
SEARCH_TYPE_STATE, // US or Canadian states
SEARCH_TYPE_COUNTRY,
TYPE_VILLAGE,
TYPE_CITY,
TYPE_STATE, // US or Canadian states
TYPE_COUNTRY,
SEARCH_TYPE_COUNT
TYPE_COUNT
};
SearchType GetSearchType(FeatureType const & feature) const;
Type GetType(FeatureType const & feature) const;
void SetCianEnabled(bool enabled) { m_cianEnabled = enabled; }
@ -55,5 +55,5 @@ private:
bool m_cianEnabled = false;
};
string DebugPrint(SearchModel::SearchType type);
string DebugPrint(Model::Type type);
} // namespace search

View file

@ -9,16 +9,16 @@ std::string DebugPrint(PreRankingInfo const & info)
std::ostringstream os;
os << "PreRankingInfo [";
os << "m_distanceToPivot:" << info.m_distanceToPivot << ",";
for (size_t i = 0; i < static_cast<size_t>(SearchModel::SEARCH_TYPE_COUNT); ++i)
for (size_t i = 0; i < static_cast<size_t>(Model::TYPE_COUNT); ++i)
{
if (info.m_tokenRange[i].Empty())
continue;
auto const type = static_cast<SearchModel::SearchType>(i);
auto const type = static_cast<Model::Type>(i);
os << "m_tokenRange[" << DebugPrint(type) << "]:" << DebugPrint(info.m_tokenRange[i]) << ",";
}
os << "m_rank:" << static_cast<int>(info.m_rank) << ",";
os << "m_searchType:" << info.m_searchType;
os << "m_type:" << info.m_type;
os << "]";
return os.str();
}

View file

@ -15,17 +15,17 @@ namespace search
{
struct PreRankingInfo
{
PreRankingInfo(SearchModel::SearchType type, TokenRange const & range)
PreRankingInfo(Model::Type type, TokenRange const & range)
{
ASSERT_LESS(type, SearchModel::SEARCH_TYPE_COUNT, ());
m_searchType = type;
m_tokenRange[m_searchType] = range;
ASSERT_LESS(type, Model::TYPE_COUNT, ());
m_type = type;
m_tokenRange[m_type] = range;
}
inline TokenRange const & InnermostTokenRange() const
{
ASSERT_LESS(m_searchType, SearchModel::SEARCH_TYPE_COUNT, ());
return m_tokenRange[m_searchType];
ASSERT_LESS(m_type, Model::TYPE_COUNT, ());
return m_tokenRange[m_type];
}
inline size_t GetNumTokens() const { return InnermostTokenRange().Size(); }
@ -38,7 +38,7 @@ struct PreRankingInfo
bool m_centerLoaded = false;
// Tokens match to the feature name or house number.
TokenRange m_tokenRange[SearchModel::SEARCH_TYPE_COUNT];
TokenRange m_tokenRange[Model::TYPE_COUNT];
// Different geo-parts extracted from query. Currently only poi,
// building and street ids are in |m_geoParts|.
@ -48,7 +48,7 @@ struct PreRankingInfo
uint8_t m_rank = 0;
// Search type for the feature.
SearchModel::SearchType m_searchType = SearchModel::SEARCH_TYPE_COUNT;
Model::Type m_type = Model::TYPE_COUNT;
};
std::string DebugPrint(PreRankingInfo const & info);

View file

@ -36,7 +36,7 @@ void UpdateNameScore(vector<strings::UniString> const & tokens, TSlice const & s
}
NameScore GetNameScore(FeatureType const & ft, Geocoder::Params const & params,
TokenRange const & range, SearchModel::SearchType type)
TokenRange const & range, Model::Type type)
{
NameScore bestScore = NAME_SCORE_ZERO;
TokenSlice slice(params, range);
@ -54,7 +54,7 @@ NameScore GetNameScore(FeatureType const & ft, Geocoder::Params const & params,
UpdateNameScore(tokens, sliceNoCategories, bestScore);
}
if (type == SearchModel::SEARCH_TYPE_BUILDING)
if (type == Model::TYPE_BUILDING)
UpdateNameScore(ft.GetHouseNumber(), sliceNoCategories, bestScore);
return bestScore;
@ -209,19 +209,18 @@ class PreResult2Maker
info.m_distanceToPivot = MercatorBounds::DistanceOnEarth(center, pivot);
info.m_rank = preInfo.m_rank;
info.m_searchType = preInfo.m_searchType;
info.m_nameScore = GetNameScore(ft, m_params, preInfo.InnermostTokenRange(), info.m_searchType);
info.m_type = preInfo.m_type;
info.m_nameScore = GetNameScore(ft, m_params, preInfo.InnermostTokenRange(), info.m_type);
if (info.m_searchType != SearchModel::SEARCH_TYPE_STREET &&
if (info.m_type != Model::TYPE_STREET &&
preInfo.m_geoParts.m_street != IntersectionResult::kInvalidId)
{
auto const & mwmId = ft.GetID().m_mwmId;
FeatureType street;
if (LoadFeature(FeatureID(mwmId, preInfo.m_geoParts.m_street), street))
{
NameScore const nameScore =
GetNameScore(street, m_params, preInfo.m_tokenRange[SearchModel::SEARCH_TYPE_STREET],
SearchModel::SEARCH_TYPE_STREET);
NameScore const nameScore = GetNameScore(
street, m_params, preInfo.m_tokenRange[Model::TYPE_STREET], Model::TYPE_STREET);
info.m_nameScore = min(info.m_nameScore, nameScore);
}
}
@ -247,13 +246,13 @@ class PreResult2Maker
});
}
uint8_t NormalizeRank(uint8_t rank, SearchModel::SearchType type, m2::PointD const & center,
uint8_t NormalizeRank(uint8_t rank, Model::Type type, m2::PointD const & center,
string const & country)
{
switch (type)
{
case SearchModel::SEARCH_TYPE_VILLAGE: return rank /= 1.5;
case SearchModel::SEARCH_TYPE_CITY:
case Model::TYPE_VILLAGE: return rank /= 1.5;
case Model::TYPE_CITY:
{
if (m_ranker.m_params.m_viewport.IsPointInside(center))
return rank * 2;
@ -266,7 +265,7 @@ class PreResult2Maker
if (info.IsNotEmpty() && info.m_name == m_ranker.m_params.m_pivotRegion)
return rank *= 1.7;
}
case SearchModel::SEARCH_TYPE_COUNTRY:
case Model::TYPE_COUNTRY:
return rank /= 1.5;
// For all other search types, rank should be zero for now.
@ -297,7 +296,7 @@ public:
search::RankingInfo info;
InitRankingInfo(ft, center, res1, info);
info.m_rank = NormalizeRank(info.m_rank, info.m_searchType, center, country);
info.m_rank = NormalizeRank(info.m_rank, info.m_type, center, country);
res2->SetRankingInfo(move(info));
return res2;

View file

@ -22,7 +22,7 @@ double const kNameScore[NameScore::NAME_SCORE_COUNT] = {
, 0.05384830009390816 /* Full Match */
};
double const kSearchType[SearchModel::SEARCH_TYPE_COUNT] = {
double const kType[Model::TYPE_COUNT] = {
-0.09164609318265761 /* POI */
, -0.09164609318265761 /* Building */
, -0.0805969548653964 /* Street */
@ -60,7 +60,7 @@ string DebugPrint(RankingInfo const & info)
os << "m_distanceToPivot:" << info.m_distanceToPivot << ",";
os << "m_rank:" << static_cast<int>(info.m_rank) << ",";
os << "m_nameScore:" << DebugPrint(info.m_nameScore) << ",";
os << "m_searchType:" << DebugPrint(info.m_searchType) << ",";
os << "m_type:" << DebugPrint(info.m_type) << ",";
os << "m_pureCats:" << info.m_pureCats << ",";
os << "m_falseCats:" << info.m_falseCats;
os << "]";
@ -71,7 +71,7 @@ void RankingInfo::ToCSV(ostream & os) const
{
os << fixed;
os << m_distanceToPivot << "," << static_cast<int>(m_rank) << "," << DebugPrint(m_nameScore)
<< "," << DebugPrint(m_searchType) << "," << m_pureCats << "," << m_falseCats;
<< "," << DebugPrint(m_type) << "," << m_pureCats << "," << m_falseCats;
}
double RankingInfo::GetLinearModelRank() const
@ -95,8 +95,8 @@ double RankingInfo::GetLinearModelRank() const
nameScore = NAME_SCORE_ZERO;
}
return kDistanceToPivot * distanceToPivot + kRank * rank + kNameScore[nameScore] +
kSearchType[m_searchType] + m_falseCats * kFalseCats;
return kDistanceToPivot * distanceToPivot + kRank * rank + kNameScore[nameScore] + kType[m_type] +
m_falseCats * kFalseCats;
}
} // namespace search

View file

@ -24,7 +24,7 @@ struct RankingInfo
NameScore m_nameScore = NAME_SCORE_ZERO;
// Search type for the feature.
SearchModel::SearchType m_searchType = SearchModel::SEARCH_TYPE_COUNT;
Model::Type m_type = Model::TYPE_COUNT;
// True if all of the tokens that the feature was matched by
// correspond to this feature's categories.

View file

@ -131,7 +131,7 @@ UNIT_CLASS_TEST(PreRankerTest, Smoke)
FeaturesVectorTest fv(mwmId.GetInfo()->GetLocalFile().GetPath(MapOptions::Map));
fv.GetVector().ForEach([&](FeatureType & ft, uint32_t index) {
FeatureID id(mwmId, index);
preRanker.Emplace(id, PreRankingInfo(SearchModel::SEARCH_TYPE_POI, TokenRange(0, 1)));
preRanker.Emplace(id, PreRankingInfo(Model::TYPE_POI, TokenRange(0, 1)));
TEST_LESS(index, pois.size(), ());
distances[index] = MercatorBounds::DistanceOnEarth(feature::GetCenter(ft), kPivot);