Adds a limit for number of results returned in Nearest service, resolves #2872
This commit is contained in:
committed by
Moritz Kobitzsch
parent
e6fe9d0d67
commit
e3c1b133bf
@@ -146,7 +146,7 @@ Engine::Engine(EngineConfig &config)
|
||||
|
||||
route_plugin = create<ViaRoutePlugin>(*query_data_facade, config.max_locations_viaroute);
|
||||
table_plugin = create<TablePlugin>(*query_data_facade, config.max_locations_distance_table);
|
||||
nearest_plugin = create<NearestPlugin>(*query_data_facade);
|
||||
nearest_plugin = create<NearestPlugin>(*query_data_facade, config.max_results_nearest);
|
||||
trip_plugin = create<TripPlugin>(*query_data_facade, config.max_locations_trip);
|
||||
match_plugin = create<MatchPlugin>(*query_data_facade, config.max_locations_map_matching);
|
||||
tile_plugin = create<TilePlugin>(*query_data_facade);
|
||||
|
||||
@@ -15,11 +15,15 @@ bool EngineConfig::IsValid() const
|
||||
storage_config.datasource_names_path.empty() &&
|
||||
storage_config.datasource_indexes_path.empty() && storage_config.names_data_path.empty();
|
||||
|
||||
const bool limits_valid =
|
||||
(max_locations_distance_table == -1 || max_locations_distance_table > 2) &&
|
||||
(max_locations_map_matching == -1 || max_locations_map_matching > 2) &&
|
||||
(max_locations_trip == -1 || max_locations_trip > 2) &&
|
||||
(max_locations_viaroute == -1 || max_locations_viaroute > 2);
|
||||
const auto unlimited_or_more_than = [](const int v, const int limit) {
|
||||
return v == -1 || v > limit;
|
||||
};
|
||||
|
||||
const bool limits_valid = unlimited_or_more_than(max_locations_distance_table, 2) &&
|
||||
unlimited_or_more_than(max_locations_map_matching, 2) &&
|
||||
unlimited_or_more_than(max_locations_trip, 2) &&
|
||||
unlimited_or_more_than(max_locations_viaroute, 2) &&
|
||||
unlimited_or_more_than(max_results_nearest, 0);
|
||||
|
||||
return ((use_shared_memory && all_path_are_empty) || storage_config.IsValid()) && limits_valid;
|
||||
}
|
||||
|
||||
@@ -16,13 +16,24 @@ namespace engine
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade) : BasePlugin{facade} {}
|
||||
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results_)
|
||||
: BasePlugin{facade}, max_results{max_results_}
|
||||
{
|
||||
}
|
||||
|
||||
Status NearestPlugin::HandleRequest(const api::NearestParameters ¶ms,
|
||||
util::json::Object &json_result)
|
||||
{
|
||||
BOOST_ASSERT(params.IsValid());
|
||||
|
||||
if (params.number_of_results > max_results)
|
||||
{
|
||||
return Error("TooBig",
|
||||
"Number of results " + std::to_string(params.number_of_results) +
|
||||
" is higher than current maximum (" + std::to_string(max_results) + ")",
|
||||
json_result);
|
||||
}
|
||||
|
||||
if (!CheckAllCoordinates(params.coordinates))
|
||||
return Error("InvalidOptions", "Coordinates are invalid", json_result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user