[search] Enable cuisine filter for requests which exact match cuisine category.

This commit is contained in:
tatiana-yan 2018-09-13 17:21:32 +03:00 committed by mpimenov
parent 44b2c83c77
commit f07b8ea3f3
7 changed files with 53 additions and 1 deletions

View file

@ -219,6 +219,8 @@ class IsFoodChecker : public BaseChecker
IsFoodChecker();
public:
DECLARE_CHECKER_INSTANCE(IsFoodChecker);
std::vector<uint32_t> const & GetTypes() const { return m_types; }
};
class IsCuisineChecker : public BaseChecker

View file

@ -1,5 +1,6 @@
#include "search/cuisine_filter.hpp"
#include "indexer/cuisines.hpp"
#include "indexer/feature.hpp"
#include "indexer/feature_meta.hpp"
#include "indexer/ftypes_matcher.hpp"
@ -23,6 +24,24 @@ void Description::FromFeature(FeatureType & ft)
if (ftypes::IsCuisineChecker::Instance().IsMatched(t))
m_types.push_back(t);
});
// Old maps support.
if (!m_types.empty())
return;
auto const & metadata = ft.GetMetadata();
if (!metadata.Has(feature::Metadata::FMD_CUISINE))
return;
string const rawCuisines = metadata.Get(feature::Metadata::FMD_CUISINE);
vector<string> cuisines;
osm::Cuisines::Instance().Parse(rawCuisines, cuisines);
for (auto const & c : cuisines)
{
auto const t = classif().GetTypeByPathSafe({"cuisine", c});
if (t != 0)
m_types.push_back(t);
}
}
CuisineFilter::ScopedFilter::ScopedFilter(MwmSet::MwmId const & mwmId,

View file

@ -345,7 +345,9 @@ Geocoder::Geocoder(DataSource const & dataSource, storage::CountryInfoGetter con
, m_streetsCache(cancellable)
, m_villagesCache(villagesCache)
, m_hotelsCache(cancellable)
, m_foodCache(cancellable)
, m_hotelsFilter(m_hotelsCache)
, m_cuisineFilter(m_foodCache)
, m_cancellable(cancellable)
, m_citiesBoundaries(citiesBoundaries)
, m_pivotRectsCache(kPivotRectsCacheSize, m_cancellable, Processor::kMaxViewportRadiusM)
@ -447,7 +449,9 @@ void Geocoder::ClearCaches()
m_matchersCache.clear();
m_streetsCache.Clear();
m_hotelsCache.Clear();
m_foodCache.Clear();
m_hotelsFilter.ClearCaches();
m_cuisineFilter.ClearCaches();
m_postcodes.Clear();
}
@ -596,6 +600,7 @@ void Geocoder::InitBaseContext(BaseContext & ctx)
}
ctx.m_hotelsFilter = m_hotelsFilter.MakeScopedFilter(*m_context, m_params.m_hotelsFilter);
ctx.m_cuisineFilter = m_cuisineFilter.MakeScopedFilter(*m_context, m_params.m_cuisineTypes);
}
void Geocoder::InitLayer(Model::Type type, TokenRange const & tokenRange, FeaturesLayer & layer)
@ -1318,7 +1323,10 @@ void Geocoder::EmitResult(BaseContext & ctx, MwmSet::MwmId const & mwmId, uint32
FeatureID id(mwmId, ftId);
if (ctx.m_hotelsFilter && !ctx.m_hotelsFilter->Matches(id))
return;
return;
if (ctx.m_cuisineFilter && !ctx.m_cuisineFilter->Matches(id))
return;
if (m_params.m_tracer)
TraceResult(*m_params.m_tracer, ctx, mwmId, ftId, type, tokenRange);

View file

@ -4,6 +4,7 @@
#include "search/categories_cache.hpp"
#include "search/cbv.hpp"
#include "search/cities_boundaries_table.hpp"
#include "search/cuisine_filter.hpp"
#include "search/feature_offset_match.hpp"
#include "search/features_layer.hpp"
#include "search/features_layer_path_finder.hpp"
@ -85,6 +86,7 @@ public:
m2::PointD m_position;
Locales m_categoryLocales;
shared_ptr<hotels_filter::Rule> m_hotelsFilter;
vector<uint32_t> m_cuisineTypes;
vector<uint32_t> m_preferredTypes;
shared_ptr<Tracer> m_tracer;
};
@ -249,7 +251,9 @@ private:
StreetsCache m_streetsCache;
VillagesCache & m_villagesCache;
HotelsCache m_hotelsCache;
FoodCache m_foodCache;
hotels_filter::HotelsFilter m_hotelsFilter;
cuisine_filter::CuisineFilter m_cuisineFilter;
base::Cancellable const & m_cancellable;

View file

@ -1,6 +1,7 @@
#pragma once
#include "search/cbv.hpp"
#include "search/cuisine_filter.hpp"
#include "search/features_layer.hpp"
#include "search/geocoder_locality.hpp"
#include "search/hotels_filter.hpp"
@ -78,6 +79,7 @@ struct BaseContext
// size_t m_numEmitted = 0;
std::unique_ptr<hotels_filter::HotelsFilter::ScopedFilter> m_hotelsFilter;
std::unique_ptr<cuisine_filter::CuisineFilter::ScopedFilter> m_cuisineFilter;
};
std::string DebugPrint(BaseContext::TokenType type);

View file

@ -1,6 +1,7 @@
#include "processor.hpp"
#include "search/common.hpp"
#include "search/cuisine_filter.hpp"
#include "search/dummy_rank_table.hpp"
#include "search/geometry_utils.hpp"
#include "search/intermediate_result.hpp"
@ -25,6 +26,7 @@
#include "indexer/feature_data.hpp"
#include "indexer/feature_impl.hpp"
#include "indexer/features_vector.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/scales.hpp"
#include "indexer/search_delimiters.hpp"
#include "indexer/search_string_utils.hpp"
@ -277,6 +279,19 @@ void Processor::SetQuery(string const & query)
auto const tokenSlice = QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix);
m_isCategorialRequest = FillCategories(tokenSlice, GetCategoryLocales(), m_categories, m_preferredTypes);
// Try to match query to cuisine categories.
if (!m_isCategorialRequest)
{
bool const isCuisineRequest = FillCategories(
tokenSlice, GetCategoryLocales(), GetDefaultCuisineCategories(), m_cuisineTypes);
if (isCuisineRequest)
{
m_isCategorialRequest = true;
m_preferredTypes = ftypes::IsFoodChecker::Instance().GetTypes();
}
}
if (!m_isCategorialRequest)
ForEachCategoryType(tokenSlice, [&](size_t, uint32_t t) { m_preferredTypes.push_back(t); });
@ -547,6 +562,7 @@ void Processor::InitGeocoder(Geocoder::Params & geocoderParams, SearchParams con
geocoderParams.m_position = GetPosition();
geocoderParams.m_categoryLocales = GetCategoryLocales();
geocoderParams.m_hotelsFilter = searchParams.m_hotelsFilter;
geocoderParams.m_cuisineTypes = m_cuisineTypes;
geocoderParams.m_preferredTypes = m_preferredTypes;
geocoderParams.m_tracer = searchParams.m_tracer;

View file

@ -124,6 +124,7 @@ protected:
strings::UniString m_prefix;
bool m_isCategorialRequest;
std::vector<uint32_t> m_preferredTypes;
std::vector<uint32_t> m_cuisineTypes;
m2::RectD m_viewport;
m2::PointD m_position;