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

intermediate_result.hpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 840b4db8acb1b11881298203eb361ead9ec3a02b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once

#include "search/result.hpp"
#include "search/v2/pre_ranking_info.hpp"
#include "search/v2/ranking_info.hpp"
#include "search/v2/ranking_utils.hpp"

#include "indexer/feature_data.hpp"

class FeatureType;
class CategoriesHolder;

namespace storage
{
class CountryInfoGetter;
struct CountryInfo;
}

namespace search
{
class ReverseGeocoder;

namespace impl
{
/// First pass results class. Objects are creating during search in trie.
/// Works fast without feature loading and provide ranking.
class PreResult1
{
public:
  PreResult1(FeatureID const & fID, v2::PreRankingInfo const & info);

  static bool LessRank(PreResult1 const & r1, PreResult1 const & r2);
  static bool LessDistance(PreResult1 const & r1, PreResult1 const & r2);

  inline FeatureID GetId() const { return m_id; }
  inline double GetDistance() const { return m_info.m_distanceToPivot; }
  inline uint8_t GetRank() const { return m_info.m_rank; }
  inline v2::PreRankingInfo & GetInfo() { return m_info; }
  inline v2::PreRankingInfo const & GetInfo() const { return m_info; }

private:
  friend class PreResult2;

  FeatureID m_id;
  v2::PreRankingInfo m_info;
};

/// Second result class. Objects are creating during reading of features.
/// Read and fill needed info for ranking and getting final results.
class PreResult2
{
  friend class PreResult2Maker;

public:
  enum ResultType
  {
    RESULT_LATLON,
    RESULT_FEATURE,
    RESULT_BUILDING  //!< Buildings are not filtered out in duplicates filter.
  };

  /// For RESULT_FEATURE and RESULT_BUILDING.
  PreResult2(FeatureType const & f, PreResult1 const * p, m2::PointD const & center,
             m2::PointD const & pivot, string const & displayName, string const & fileName);

  /// For RESULT_LATLON.
  PreResult2(double lat, double lon);

  inline search::v2::RankingInfo const & GetRankingInfo() const { return m_info; }

  template <typename TInfo>
  inline void SetRankingInfo(TInfo && info)
  {
    m_info = forward<TInfo>(info);
  }

  /// @param[in]  infoGetter Need to get region for result.
  /// @param[in]  pCat    Categories need to display readable type string.
  /// @param[in]  pTypes  Set of preffered types that match input tokens by categories.
  /// @param[in]  lang    Current system language.
  /// @param[in]  coder   May be nullptr - no need to calculate address.
  Result GenerateFinalResult(storage::CountryInfoGetter const & infoGetter,
                             CategoriesHolder const * pCat, set<uint32_t> const * pTypes,
                             int8_t locale, ReverseGeocoder const * coder) const;

  /// Filter equal features for different mwm's.
  class StrictEqualF
  {
    PreResult2 const & m_r;
  public:
    StrictEqualF(PreResult2 const & r) : m_r(r) {}
    bool operator() (PreResult2 const & r) const;
  };

  /// To filter equal linear objects.
  //@{
  struct LessLinearTypesF
  {
    bool operator() (PreResult2 const & r1, PreResult2 const & r2) const;
  };
  class EqualLinearTypesF
  {
  public:
    bool operator() (PreResult2 const & r1, PreResult2 const & r2) const;
  };
  //@}

  string DebugPrint() const;

  bool IsStreet() const;

  inline FeatureID const & GetID() const { return m_id; }
  inline string const & GetName() const { return m_str; }
  inline feature::TypesHolder const & GetTypes() const { return m_types; }
  inline m2::PointD GetCenter() const { return m_region.m_point; }

private:
  bool IsEqualCommon(PreResult2 const & r) const;

  FeatureID m_id;
  feature::TypesHolder m_types;

  uint32_t GetBestType(set<uint32_t> const * pPrefferedTypes = 0) const;

  string m_str;

  struct RegionInfo
  {
    string m_file;
    m2::PointD m_point;

    inline void SetParams(string const & file, m2::PointD const & pt)
    {
      m_file = file;
      m_point = pt;
    }

    void GetRegion(storage::CountryInfoGetter const & infoGetter,
                   storage::CountryInfo & info) const;
  } m_region;

  string GetRegionName(storage::CountryInfoGetter const & infoGetter, uint32_t fType) const;

  double m_distance;
  ResultType m_resultType;
  v2::RankingInfo m_info;
  feature::EGeomType m_geomType;

  Result::Metadata m_metadata;
};

inline string DebugPrint(PreResult2 const & t)
{
  return t.DebugPrint();
}
}  // namespace impl

void ProcessMetadata(FeatureType const & ft, Result::Metadata & meta);
}  // namespace search