From 6d388bc614a868ffdfa04431f05f631321853933 Mon Sep 17 00:00:00 2001 From: Anatoly Serdtcev Date: Fri, 29 Nov 2019 16:48:48 +0300 Subject: [PATCH] [geocoder] Fix for integration tests: stable order of equal rank candidates --- geocoder/geocoder.cpp | 14 +++++++++----- geocoder/geocoder.hpp | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/geocoder/geocoder.cpp b/geocoder/geocoder.cpp index 01fcc60..f380c45 100644 --- a/geocoder/geocoder.cpp +++ b/geocoder/geocoder.cpp @@ -153,15 +153,19 @@ strings::UniString MakeHouseNumber(Tokens const & tokens) } // namespace // Geocoder::Layer --------------------------------------------------------------------------------- -Geocoder::Layer::Layer(Type type) - : m_type{type} +Geocoder::Layer::Layer(Index const & index, Type type) + : m_index{index}, m_type{type} { } void Geocoder::Layer::SetCandidates(std::vector && candidates) { - std::sort(candidates.begin(), candidates.end(), [](auto const & a, auto const & b) { - return a.m_totalCertainty < b.m_totalCertainty; + std::sort(candidates.begin(), candidates.end(), [this](auto const & a, auto const & b) { + if (a.m_totalCertainty < b.m_totalCertainty) + return true; + if (a.m_totalCertainty > b.m_totalCertainty) + return false; + return m_index.GetDoc(a.m_entry).m_osmId < m_index.GetDoc(b.m_entry).m_osmId; }); m_candidatesByCertainty = std::move(candidates); } @@ -418,7 +422,7 @@ void Geocoder::Go(Context & ctx, Type type) const subquery.push_back(ctx.GetToken(j)); subqueryTokenIds.push_back(j); - Layer curLayer{type}; + Layer curLayer{m_index, type}; // Buildings are indexed separately. if (type == Type::Building) diff --git a/geocoder/geocoder.hpp b/geocoder/geocoder.hpp index af70ec3..bda87f0 100644 --- a/geocoder/geocoder.hpp +++ b/geocoder/geocoder.hpp @@ -57,8 +57,7 @@ public: class Layer { public: - Layer() = default; - Layer(Type type); + Layer(Index const & index, Type type); Type GetType() const noexcept { return m_type; } std::vector const & GetCandidatesByCertainty() const noexcept @@ -68,6 +67,7 @@ public: void SetCandidates(std::vector && candidates); private: + Index const & m_index; Type m_type{Type::Count}; std::vector m_candidatesByCertainty; };