diff options
Diffstat (limited to 'search')
-rw-r--r-- | search/processor.cpp | 3 | ||||
-rw-r--r-- | search/retrieval.cpp | 19 | ||||
-rw-r--r-- | search/search_integration_tests/search_edited_features_test.cpp | 65 | ||||
-rw-r--r-- | search/search_tests_support/test_results_matching.cpp | 2 | ||||
-rw-r--r-- | search/search_tests_support/test_results_matching.hpp | 5 |
5 files changed, 85 insertions, 9 deletions
diff --git a/search/processor.cpp b/search/processor.cpp index 9dd4deaf98..4c96b0c704 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -377,6 +377,7 @@ void Processor::ForEachCategoryType(StringSliceBase const & slice, ToDo && todo) void Processor::Search(SearchParams const & params, m2::RectD const & viewport) { + SetMode(params.m_mode); bool const viewportSearch = m_mode == Mode::Viewport; bool rankPivotIsSet = false; @@ -399,8 +400,8 @@ void Processor::Search(SearchParams const & params, m2::RectD const & viewport) SetMinDistanceOnMapBetweenResults(params.m_minDistanceOnMapBetweenResults); - SetMode(params.m_mode); SetSuggestsEnabled(params.m_suggestsEnabled); + SetInputLocale(params.m_inputLocale); ASSERT(!params.m_query.empty(), ()); diff --git a/search/retrieval.cpp b/search/retrieval.cpp index fb0587d3a4..2c25219706 100644 --- a/search/retrieval.cpp +++ b/search/retrieval.cpp @@ -263,14 +263,25 @@ unique_ptr<coding::CompressedBitVector> RetrievePostcodeFeaturesImpl( // Retrieves from the geometry index corresponding to handle all // features from |coverage|. unique_ptr<coding::CompressedBitVector> RetrieveGeometryFeaturesImpl( - MwmContext const & context, my::Cancellable const & cancellable, - covering::IntervalsT const & coverage, int scale) + MwmContext const & context, my::Cancellable const & cancellable, m2::RectD const & rect, + int scale) { + EditedFeaturesHolder holder(context.GetId()); + + covering::IntervalsT coverage; + CoverRect(rect, scale, coverage); + vector<uint64_t> features; FeaturesCollector collector(cancellable, features); context.ForEachIndex(coverage, scale, collector); + + holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index) { + auto const center = feature::GetCenter(ft); + if (rect.IsPointInside(center)) + features.push_back(index); + }); return SortFeaturesAndBuildCBV(move(features)); } @@ -338,8 +349,6 @@ unique_ptr<coding::CompressedBitVector> RetrieveGeometryFeatures( MwmContext const & context, my::Cancellable const & cancellable, m2::RectD const & rect, int scale) { - covering::IntervalsT coverage; - CoverRect(rect, scale, coverage); - return RetrieveGeometryFeaturesImpl(context, cancellable, coverage, scale); + return RetrieveGeometryFeaturesImpl(context, cancellable, rect, scale); } } // namespace search diff --git a/search/search_integration_tests/search_edited_features_test.cpp b/search/search_integration_tests/search_edited_features_test.cpp index bd3ed5c7f0..003ecb2c08 100644 --- a/search/search_integration_tests/search_edited_features_test.cpp +++ b/search/search_integration_tests/search_edited_features_test.cpp @@ -59,4 +59,69 @@ UNIT_CLASS_TEST(SearchEditedFeaturesTest, Smoke) TEST(ResultsMatch("wifi bar quahog", rules), ()); } } + +UNIT_CLASS_TEST(SearchEditedFeaturesTest, SearchInViewport) +{ + TestCity city(m2::PointD(0, 0), "Canterlot", "default", 100 /* rank */); + TestPOI bakery0(m2::PointD(0, 0), "Bakery 0", "default"); + TestPOI cornerPost(m2::PointD(100, 100), "Corner Post", "default"); + auto & editor = osm::Editor::Instance(); + + BuildWorld([&](TestMwmBuilder & builder) { builder.Add(city); }); + + auto const countryId = BuildCountry("Equestria", [&](TestMwmBuilder & builder) { + builder.Add(bakery0); + builder.Add(cornerPost); + }); + + auto const tmp1 = TestPOI::AddWithEditor(editor, countryId, "bakery1", {1.0, 1.0}); + TestPOI const & bakery1 = tmp1.first; + FeatureID const & id1 = tmp1.second; + auto const tmp2 = TestPOI::AddWithEditor(editor, countryId, "bakery2", {2.0, 2.0}); + TestPOI const & bakery2 = tmp2.first; + FeatureID const & id2 = tmp2.second; + auto const tmp3 = TestPOI::AddWithEditor(editor, countryId, "bakery3", {3.0, 3.0}); + TestPOI const & bakery3 = tmp3.first; + FeatureID const & id3 = tmp3.second; + UNUSED_VALUE(id2); + + SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1), + ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(-2.0, -2.0, -1.0, -1.0)); + { + TRules const rules = {}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(-1.0, -1.0, 1.5, 1.5)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(1.5, 1.5, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + editor.DeleteFeature(id1); + editor.DeleteFeature(id3); + + SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery2)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } +} } // namespace diff --git a/search/search_tests_support/test_results_matching.cpp b/search/search_tests_support/test_results_matching.cpp index 34d8a3e1b9..ccbfa55b7f 100644 --- a/search/search_tests_support/test_results_matching.cpp +++ b/search/search_tests_support/test_results_matching.cpp @@ -13,7 +13,7 @@ namespace search { namespace tests_support { -ExactMatchingRule::ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature) +ExactMatchingRule::ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature const & feature) : m_mwmId(mwmId), m_feature(feature) { } diff --git a/search/search_tests_support/test_results_matching.hpp b/search/search_tests_support/test_results_matching.hpp index 24505d369e..3a776d48ca 100644 --- a/search/search_tests_support/test_results_matching.hpp +++ b/search/search_tests_support/test_results_matching.hpp @@ -35,7 +35,8 @@ public: class ExactMatchingRule : public MatchingRule { public: - ExactMatchingRule(MwmSet::MwmId const & mwmId, generator::tests_support::TestFeature & feature); + ExactMatchingRule(MwmSet::MwmId const & mwmId, + generator::tests_support::TestFeature const & feature); // MatchingRule overrides: bool Matches(FeatureType const & feature) const override; @@ -43,7 +44,7 @@ public: private: MwmSet::MwmId m_mwmId; - generator::tests_support::TestFeature & m_feature; + generator::tests_support::TestFeature const & m_feature; }; class AlternativesMatchingRule : public MatchingRule |