Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/search
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2019-02-08 15:06:19 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2019-02-20 20:49:23 +0300
commit6e830e8ac5a3f9b35d4c63eb7384d948f019ab3c (patch)
treec8daef8ad5c84ec51eff7c896f4cd4a456b39476 /search
parentce161beb47921be5b9612ad94e37473d6206dcf7 (diff)
[search] Separated the ResultTracer.
Diffstat (limited to 'search')
-rw-r--r--search/geocoder.cpp32
-rw-r--r--search/geocoder.hpp4
-rw-r--r--search/intermediate_result.cpp2
-rw-r--r--search/intermediate_result.hpp10
-rw-r--r--search/pre_ranker.cpp24
-rw-r--r--search/pre_ranker.hpp3
-rw-r--r--search/pre_ranking_info.hpp1
-rw-r--r--search/processor.cpp2
-rw-r--r--search/ranker.cpp2
-rw-r--r--search/ranking_info.cpp4
-rw-r--r--search/result.cpp4
-rw-r--r--search/result.hpp4
-rw-r--r--search/search_integration_tests/processor_test.cpp16
-rw-r--r--search/search_tests_support/test_search_request.cpp5
-rw-r--r--search/tracer.cpp34
-rw-r--r--search/tracer.hpp47
16 files changed, 108 insertions, 86 deletions
diff --git a/search/geocoder.cpp b/search/geocoder.cpp
index 3a64b1c9b5..b6d1e41854 100644
--- a/search/geocoder.cpp
+++ b/search/geocoder.cpp
@@ -313,21 +313,9 @@ size_t OrderCountries(boost::optional<m2::PointD> const & position, m2::RectD co
return distance(infos.begin(), sep);
}
-void TraceEntrance(shared_ptr<Tracer> tracer, Tracer::Branch branch)
-{
- if (tracer != nullptr)
- tracer->CallMethod(branch);
-}
-
-void TraceExit(shared_ptr<Tracer> tracer, Tracer::Branch branch)
-{
- if (tracer != nullptr)
- tracer->LeaveMethod(branch);
-}
-
-#define TRACE(branch) \
- TraceEntrance(m_params.m_tracer, Tracer::Branch::branch); \
- SCOPE_GUARD(tracerGuard, [&] { TraceExit(m_params.m_tracer, Tracer::Branch::branch); });
+#define TRACE(branch) \
+ m_resultTracer.CallMethod(ResultTracer::Branch::branch); \
+ SCOPE_GUARD(tracerGuard, [&] { m_resultTracer.LeaveMethod(ResultTracer::Branch::branch); });
} // namespace
// Geocoder::Geocoder ------------------------------------------------------------------------------
@@ -396,6 +384,8 @@ void Geocoder::SetParams(Params const & params)
}
}
+ m_resultTracer.Clear();
+
LOG(LDEBUG, (static_cast<QueryParams const &>(m_params)));
}
@@ -1043,13 +1033,14 @@ void Geocoder::CreateStreetsLayerAndMatchLowerLayers(BaseContext & ctx,
ScopedMarkTokens mark(ctx.m_tokens, BaseContext::TOKEN_TYPE_STREET, prediction.m_tokenRange);
size_t const numEmitted = ctx.m_numEmitted;
- LOG(LINFO, ("num emitted1", ctx.m_numEmitted));
MatchPOIsAndBuildings(ctx, 0 /* curToken */);
- LOG(LINFO, ("num emitted2", ctx.m_numEmitted));
// A relaxed best effort parse: at least show the street if we can find one.
- if (numEmitted == ctx.m_numEmitted)
+ if (numEmitted == ctx.m_numEmitted && ctx.SkipUsedTokens(0) != ctx.m_numTokens)
+ {
+ TRACE(Relaxed);
FindPaths(ctx);
+ }
}
void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken)
@@ -1377,10 +1368,7 @@ void Geocoder::EmitResult(BaseContext & ctx, MwmSet::MwmId const & mwmId, uint32
info.m_allTokensUsed = allTokensUsed;
- if (m_params.m_tracer == nullptr)
- m_preRanker.Emplace(id, info, Tracer::Provenance{});
- else
- m_preRanker.Emplace(id, info, m_params.m_tracer->GetProvenance());
+ m_preRanker.Emplace(id, info, m_resultTracer.GetProvenance());
++ctx.m_numEmitted;
}
diff --git a/search/geocoder.hpp b/search/geocoder.hpp
index 7ea93bcdad..494c1714ff 100644
--- a/search/geocoder.hpp
+++ b/search/geocoder.hpp
@@ -21,6 +21,7 @@
#include "search/ranking_utils.hpp"
#include "search/streets_matcher.hpp"
#include "search/token_range.hpp"
+#include "search/tracer.hpp"
#include "indexer/mwm_set.hpp"
@@ -62,7 +63,6 @@ class FeaturesFilter;
class FeaturesLayerMatcher;
class PreRanker;
class TokenSlice;
-class Tracer;
// This class is used to retrieve all features corresponding to a
// search query. Search query is represented as a sequence of tokens
@@ -304,6 +304,8 @@ private:
std::vector<SearchTrieRequest<strings::LevenshteinDFA>> m_tokenRequests;
SearchTrieRequest<strings::PrefixDFAModifier<strings::LevenshteinDFA>> m_prefixTokenRequest;
+ ResultTracer m_resultTracer;
+
PreRanker & m_preRanker;
};
} // namespace search
diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp
index ce201796ad..563b3f03a9 100644
--- a/search/intermediate_result.cpp
+++ b/search/intermediate_result.cpp
@@ -73,7 +73,7 @@ PreRankerResult::PreRankerResult(FeatureID const & id, PreRankingInfo const & in
}
PreRankerResult::PreRankerResult(FeatureID const & id, PreRankingInfo const & info,
- vector<Tracer::Branch> const & provenance)
+ vector<ResultTracer::Branch> const & provenance)
: m_id(id), m_info(info), m_provenance(provenance)
{
ASSERT(m_id.IsValid(), ());
diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp
index 856d9c74da..6b0058e258 100644
--- a/search/intermediate_result.hpp
+++ b/search/intermediate_result.hpp
@@ -35,7 +35,7 @@ public:
PreRankerResult(FeatureID const & id, PreRankingInfo const & info);
PreRankerResult(FeatureID const & id, PreRankingInfo const & info,
- std::vector<Tracer::Branch> const & provenance);
+ std::vector<ResultTracer::Branch> const & provenance);
static bool LessRankAndPopularity(PreRankerResult const & r1, PreRankerResult const & r2);
static bool LessDistance(PreRankerResult const & r1, PreRankerResult const & r2);
@@ -55,7 +55,7 @@ public:
uint8_t GetPopularity() const { return m_info.m_popularity; }
PreRankingInfo & GetInfo() { return m_info; }
PreRankingInfo const & GetInfo() const { return m_info; }
- std::vector<Tracer::Branch> const & GetProvenance() const { return m_provenance; }
+ std::vector<ResultTracer::Branch> const & GetProvenance() const { return m_provenance; }
private:
friend class RankerResult;
@@ -64,7 +64,7 @@ private:
PreRankingInfo m_info;
// The call path in the Geocoder that leads to this result.
- std::vector<Tracer::Branch> m_provenance;
+ std::vector<ResultTracer::Branch> m_provenance;
};
// Second result class. Objects are created during reading of features.
@@ -115,7 +115,7 @@ public:
uint32_t GetBestType(std::vector<uint32_t> const & preferredTypes = {}) const;
- std::vector<Tracer::Branch> const & GetProvenance() const { return m_provenance; }
+ std::vector<ResultTracer::Branch> const & GetProvenance() const { return m_provenance; }
private:
friend class RankerResultMaker;
@@ -146,7 +146,7 @@ private:
Result::Metadata m_metadata;
// The call path in the Geocoder that leads to this result.
- std::vector<Tracer::Branch> m_provenance;
+ std::vector<ResultTracer::Branch> m_provenance;
};
void ProcessMetadata(FeatureType & ft, Result::Metadata & meta);
diff --git a/search/pre_ranker.cpp b/search/pre_ranker.cpp
index 3eb0df01d7..d4c20193c3 100644
--- a/search/pre_ranker.cpp
+++ b/search/pre_ranker.cpp
@@ -3,6 +3,7 @@
#include "search/dummy_rank_table.hpp"
#include "search/lazy_centers_table.hpp"
#include "search/pre_ranking_info.hpp"
+#include "search/tracer.hpp"
#include "indexer/data_source.hpp"
#include "indexer/mwm_set.hpp"
@@ -15,6 +16,7 @@
#include "base/random.hpp"
#include "base/stl_helpers.hpp"
+#include <algorithm>
#include <iterator>
#include <set>
@@ -56,6 +58,7 @@ void PreRanker::Init(Params const & params)
{
m_numSentResults = 0;
m_results.clear();
+ m_relaxedResults.clear();
m_params = params;
m_currEmit.clear();
}
@@ -222,8 +225,10 @@ void PreRanker::Filter(bool viewportSearch)
void PreRanker::UpdateResults(bool lastUpdate)
{
+ FilterRelaxedResults(lastUpdate);
FillMissingFieldsInPreResults();
Filter(m_params.m_viewportSearch);
+ LOG(LINFO, ("sending", m_results.size(), "results to ranker"));
m_numSentResults += m_results.size();
m_ranker.SetPreRankerResults(move(m_results));
m_results.clear();
@@ -313,4 +318,23 @@ void PreRanker::FilterForViewportSearch()
m_results.push_back(results[i]);
}
}
+
+void PreRanker::FilterRelaxedResults(bool lastUpdate)
+{
+ if (lastUpdate)
+ {
+ m_results.insert(m_results.end(), m_relaxedResults.begin(), m_relaxedResults.end());
+ m_relaxedResults.clear();
+ }
+ else
+ {
+ auto const isNotRelaxed = [](PreRankerResult const & res) {
+ auto const & prov = res.GetProvenance();
+ return find(prov.begin(), prov.end(), ResultTracer::Branch::Relaxed) == prov.end();
+ };
+ auto const it = partition(m_results.begin(), m_results.end(), isNotRelaxed);
+ m_relaxedResults.insert(m_relaxedResults.end(), it, m_results.end());
+ m_results.erase(it, m_results.end());
+ }
+}
} // namespace search
diff --git a/search/pre_ranker.hpp b/search/pre_ranker.hpp
index 8c6806ccf5..fb7c022714 100644
--- a/search/pre_ranker.hpp
+++ b/search/pre_ranker.hpp
@@ -94,9 +94,12 @@ public:
private:
void FilterForViewportSearch();
+ void FilterRelaxedResults(bool lastUpdate);
+
DataSource const & m_dataSource;
Ranker & m_ranker;
std::vector<PreRankerResult> m_results;
+ std::vector<PreRankerResult> m_relaxedResults;
Params m_params;
// Amount of results sent up the pipeline.
diff --git a/search/pre_ranking_info.hpp b/search/pre_ranking_info.hpp
index cd5d6add9e..b19a76dd1d 100644
--- a/search/pre_ranking_info.hpp
+++ b/search/pre_ranking_info.hpp
@@ -3,7 +3,6 @@
#include "search/intersection_result.hpp"
#include "search/model.hpp"
#include "search/token_range.hpp"
-#include "search/tracer.hpp"
#include "indexer/feature_decl.hpp"
diff --git a/search/processor.cpp b/search/processor.cpp
index 001bb059fd..61dc41fd6c 100644
--- a/search/processor.cpp
+++ b/search/processor.cpp
@@ -549,8 +549,6 @@ void Processor::InitGeocoder(Geocoder::Params & geocoderParams, SearchParams con
geocoderParams.m_cuisineTypes = m_cuisineTypes;
geocoderParams.m_preferredTypes = m_preferredTypes;
geocoderParams.m_tracer = searchParams.m_tracer;
- if (geocoderParams.m_tracer == nullptr)
- geocoderParams.m_tracer = make_shared<Tracer>();
m_geocoder.SetParams(geocoderParams);
}
diff --git a/search/ranker.cpp b/search/ranker.cpp
index 0fd446290d..1fc6981a42 100644
--- a/search/ranker.cpp
+++ b/search/ranker.cpp
@@ -516,7 +516,9 @@ void Ranker::UpdateResults(bool lastUpdate)
BailIfCancelled();
MakeRankerResults(m_geocoderParams, m_tentativeResults);
+ LOG(LINFO, ("made res, size =", m_tentativeResults.size()));
RemoveDuplicatingLinear(m_tentativeResults);
+ LOG(LINFO, ("removed duplicates, size =", m_tentativeResults.size()));
if (m_tentativeResults.empty())
return;
diff --git a/search/ranking_info.cpp b/search/ranking_info.cpp
index fa1d269749..5e37a69c5e 100644
--- a/search/ranking_info.cpp
+++ b/search/ranking_info.cpp
@@ -80,8 +80,8 @@ string DebugPrint(RankingInfo const & info)
os << "m_type:" << DebugPrint(info.m_type) << ",";
os << "m_pureCats:" << info.m_pureCats << ",";
os << "m_falseCats:" << info.m_falseCats << ",";
- os << "m_allTokensUsed:" << info.m_allTokensUsed;
- os << "m_categorialRequest:" << info.m_categorialRequest;
+ os << "m_allTokensUsed:" << info.m_allTokensUsed << ",";
+ os << "m_categorialRequest:" << info.m_categorialRequest << ",";
os << "m_hasName:" << info.m_hasName;
os << "]";
return os.str();
diff --git a/search/result.cpp b/search/result.cpp
index fe9f2e7506..6083a9586a 100644
--- a/search/result.cpp
+++ b/search/result.cpp
@@ -166,9 +166,9 @@ string DebugPrint(Result const & result)
os << "Result [";
os << "name: " << result.GetString() << ", ";
os << "type: " << readableType << ", ";
- os << "info: " << DebugPrint(result.GetRankingInfo()) << ", ";
+ os << "info: " << DebugPrint(result.GetRankingInfo());
if (!result.GetProvenance().empty())
- os << "provenance: " << ::DebugPrint(result.GetProvenance());
+ os << ", provenance: " << ::DebugPrint(result.GetProvenance());
os << "]";
return os.str();
}
diff --git a/search/result.hpp b/search/result.hpp
index 450417621f..598a0241bf 100644
--- a/search/result.hpp
+++ b/search/result.hpp
@@ -131,7 +131,7 @@ public:
RankingInfo const & GetRankingInfo() const { return m_info; }
- std::vector<Tracer::Branch> const & GetProvenance() const { return m_provenance; }
+ std::vector<ResultTracer::Branch> const & GetProvenance() const { return m_provenance; }
template <typename Info>
void SetRankingInfo(Info && info)
@@ -167,7 +167,7 @@ private:
// a search query. -1 if undefined.
int32_t m_positionInResults = -1;
- std::vector<Tracer::Branch> m_provenance;
+ std::vector<ResultTracer::Branch> m_provenance;
public:
// Careful when moving: the order of destructors is important.
diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp
index d4d351a199..bdb5cbb8f3 100644
--- a/search/search_integration_tests/processor_test.cpp
+++ b/search/search_integration_tests/processor_test.cpp
@@ -285,15 +285,15 @@ UNIT_CLASS_TEST(ProcessorTest, Smoke)
{
Rules rules = {ExactMatch(wonderlandId, feynmanHouse), ExactMatch(wonderlandId, lantern1),
ExactMatch(wonderlandId, firstAprilStreet)};
- // TEST(ResultsMatch("feynman street 1", rules), ());
+ TEST(ResultsMatch("feynman street 1", rules), ());
}
{
Rules rules = {ExactMatch(wonderlandId, bohrHouse), ExactMatch(wonderlandId, hilbertHouse),
ExactMatch(wonderlandId, lantern1), ExactMatch(wonderlandId, firstAprilStreet)};
- // TEST(ResultsMatch("bohr street 1", rules), ());
+ TEST(ResultsMatch("bohr street 1", rules), ());
}
{
-// TEST(ResultsMatch("bohr street 1 unit 3", {ExactMatch(wonderlandId, bohrStreet1)}), ());
+ TEST(ResultsMatch("bohr street 1 unit 3", {ExactMatch(wonderlandId, bohrStreet1)}), ());
}
{
Rules rules = {ExactMatch(wonderlandId, lantern1), ExactMatch(wonderlandId, lantern2)};
@@ -301,7 +301,7 @@ UNIT_CLASS_TEST(ProcessorTest, Smoke)
}
{
Rules rules = {ExactMatch(wonderlandId, feynmanHouse), ExactMatch(wonderlandId, feynmanStreet)};
- // TEST(ResultsMatch("wonderland los alamos feynman 1 unit 1 ", rules), ());
+ TEST(ResultsMatch("wonderland los alamos feynman 1 unit 1 ", rules), ());
}
{
// It's possible to find Descartes house by name.
@@ -317,12 +317,12 @@ UNIT_CLASS_TEST(ProcessorTest, Smoke)
}
{
Rules rules = {ExactMatch(wonderlandId, bornHouse), ExactMatch(wonderlandId, firstAprilStreet)};
- // TEST(ResultsMatch("long pond 1st april street 8 ", rules), ());
+ TEST(ResultsMatch("long pond 1st april street 8 ", rules), ());
}
{
Rules rules = {ExactMatch(wonderlandId, terranceHouse), ExactMatch(wonderlandId, stradaDrive)};
- // TEST(ResultsMatch("Toronto strada drive 155", rules), ());
+ TEST(ResultsMatch("Toronto strada drive 155", rules), ());
}
}
@@ -1761,8 +1761,10 @@ UNIT_CLASS_TEST(ProcessorTest, SynonymsTest)
}
{
Rules rules = {ExactMatch(wonderlandId, stPeterRu)};
+ Rules relaxedRules = {ExactMatch(wonderlandId, stPeterRu),
+ ExactMatch(wonderlandId, streetRu)};
TEST(ResultsMatch("собор святого петра ", rules), ());
- TEST(ResultsMatch("собор св петра ", rules), ());
+ TEST(ResultsMatch("собор св петра ", relaxedRules), ());
}
}
diff --git a/search/search_tests_support/test_search_request.cpp b/search/search_tests_support/test_search_request.cpp
index 921266180f..75b2666b3c 100644
--- a/search/search_tests_support/test_search_request.cpp
+++ b/search/search_tests_support/test_search_request.cpp
@@ -116,16 +116,13 @@ void TestSearchRequest::OnStarted()
void TestSearchRequest::OnResults(search::Results const & results)
{
lock_guard<mutex> lock(m_mu);
+ m_results.assign(results.begin(), results.end());
if (results.IsEndMarker())
{
m_done = true;
m_endTime = m_timer.TimeElapsed();
m_cv.notify_one();
}
- else
- {
- m_results.assign(results.begin(), results.end());
- }
}
void TestSearchRequest::SetCustomOnResults(SearchParams::OnResults const & onResults)
diff --git a/search/tracer.cpp b/search/tracer.cpp
index 27121a6bea..3a6ee72a29 100644
--- a/search/tracer.cpp
+++ b/search/tracer.cpp
@@ -6,7 +6,6 @@
#include <cstddef>
#include <iomanip>
#include <sstream>
-#include <string>
using namespace std;
@@ -42,12 +41,12 @@ vector<Tracer::Parse> Tracer::GetUniqueParses() const
return parses;
}
-void Tracer::CallMethod(Branch branch)
-{
- m_provenance.emplace_back(branch);
-}
+// ResultTracer ------------------------------------------------------------------------------------
+void ResultTracer::Clear() { m_provenance.clear(); }
+
+void ResultTracer::CallMethod(Branch branch) { m_provenance.emplace_back(branch); }
-void Tracer::LeaveMethod(Branch branch)
+void ResultTracer::LeaveMethod(Branch branch)
{
CHECK(!m_provenance.empty(), ());
CHECK_EQUAL(m_provenance.back(), branch, ());
@@ -82,20 +81,21 @@ string DebugPrint(Tracer::Parse const & parse)
return os.str();
}
-string DebugPrint(Tracer::Branch branch)
+string DebugPrint(ResultTracer::Branch branch)
{
switch (branch)
{
- case Tracer::Branch::GoEverywhere: return "GoEverywhere";
- case Tracer::Branch::GoInViewport: return "GoInViewport";
- case Tracer::Branch::MatchCategories: return "MatchCategories";
- case Tracer::Branch::MatchRegions: return "MatchRegions";
- case Tracer::Branch::MatchCities: return "MatchCities";
- case Tracer::Branch::MatchAroundPivot: return "MatchAroundPivot";
- case Tracer::Branch::MatchPOIsAndBuildings: return "MatchPOIsAndBuildings";
- case Tracer::Branch::GreedilyMatchStreets: return "GreedilyMatchStreets";
- case Tracer::Branch::WithPostcodes: return "WithPostcodes";
- case Tracer::Branch::MatchUnclassified: return "MatchUnclassified";
+ case ResultTracer::Branch::GoEverywhere: return "GoEverywhere";
+ case ResultTracer::Branch::GoInViewport: return "GoInViewport";
+ case ResultTracer::Branch::MatchCategories: return "MatchCategories";
+ case ResultTracer::Branch::MatchRegions: return "MatchRegions";
+ case ResultTracer::Branch::MatchCities: return "MatchCities";
+ case ResultTracer::Branch::MatchAroundPivot: return "MatchAroundPivot";
+ case ResultTracer::Branch::MatchPOIsAndBuildings: return "MatchPOIsAndBuildings";
+ case ResultTracer::Branch::GreedilyMatchStreets: return "GreedilyMatchStreets";
+ case ResultTracer::Branch::WithPostcodes: return "WithPostcodes";
+ case ResultTracer::Branch::MatchUnclassified: return "MatchUnclassified";
+ case ResultTracer::Branch::Relaxed: return "Relaxed";
}
UNREACHABLE();
}
diff --git a/search/tracer.hpp b/search/tracer.hpp
index 7e62f1127b..fd481afce8 100644
--- a/search/tracer.hpp
+++ b/search/tracer.hpp
@@ -13,23 +13,6 @@ namespace search
class Tracer
{
public:
- // Mimics the Geocoder methods.
- enum class Branch
- {
- GoEverywhere,
- GoInViewport,
- MatchCategories,
- MatchRegions,
- MatchCities,
- MatchAroundPivot,
- MatchPOIsAndBuildings,
- GreedilyMatchStreets,
- WithPostcodes,
- MatchUnclassified,
- };
-
- using Provenance = std::vector<Branch>;
-
struct Parse
{
using TokenType = BaseContext::TokenType;
@@ -62,17 +45,41 @@ public:
std::vector<Parse> GetUniqueParses() const;
+private:
+ std::vector<Parse> m_parses;
+};
+
+class ResultTracer
+{
+public:
+ // Mimics the Geocoder methods.
+ enum class Branch
+ {
+ GoEverywhere,
+ GoInViewport,
+ MatchCategories,
+ MatchRegions,
+ MatchCities,
+ MatchAroundPivot,
+ MatchPOIsAndBuildings,
+ GreedilyMatchStreets,
+ WithPostcodes,
+ MatchUnclassified,
+ Relaxed,
+ };
+
+ using Provenance = std::vector<Branch>;
+
+ void Clear();
void CallMethod(Branch branch);
void LeaveMethod(Branch branch);
Provenance const & GetProvenance() const { return m_provenance; }
private:
- std::vector<Parse> m_parses;
-
// Traces the Geocoder call tree that leads to emitting the current result.
Provenance m_provenance;
};
std::string DebugPrint(Tracer::Parse const & parse);
-std::string DebugPrint(Tracer::Branch branch);
+std::string DebugPrint(ResultTracer::Branch branch);
} // namespace search