hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxMatchInfo.cpp
Go to the documentation of this file.
1 #include "SphinxMatchInfo.hpp"
2 #include "SphinxResultData.hpp"
3 
4 namespace HCE
5 {
6 namespace sphinx
7 {
8 //-------------------------------------------------------------------
10 : name(""), value("")
11 {
12  (*this) = rhs;
13 }
14 //-------------------------------------------------------------------
16 : name(""), value("")
17 {
18  (*this) = std::forward<AttrInfo>(rhs);
19 }
20 //-------------------------------------------------------------------
22 {
23  if (this != &rhs)
24  {
25  name = rhs.name;
26  value = rhs.value;
27  }
28  return *this;
29 }
30 //-------------------------------------------------------------------
32 {
33  if (this != &rhs)
34  {
35  name = std::move(rhs.name);
36  value = std::move(rhs.value);
37  }
38  return *this;
39 }
40 //-------------------------------------------------------------------
41 //-------------------------------------------------------------------
43 :docId(0), weight(""), attributes()
44 {
45 }
46 //-------------------------------------------------------------------
48 :docId(0), weight(""), attributes(attributesCount)
49 {
50 }
51 //-------------------------------------------------------------------
53 :docId(0), weight(""), attributes(rhs.getAttributes().size())
54 {
55  (*this) = rhs;
56 }
57 //-------------------------------------------------------------------
59 :docId(0), weight(""), attributes(rhs.getAttributes().size())
60 {
61  (*this) = std::forward<SphinxMatchInfo>(rhs);
62 }
63 //-------------------------------------------------------------------
64 void SphinxMatchInfo::setWeightFromNumeric(unsigned long long weight, unsigned long long length)
65 {
66  setWeightFromHexString(toHexString(weight, length));
67 }
68 //-------------------------------------------------------------------
70 {
71  setWeight(weight);
72 }
73 //-------------------------------------------------------------------
74 // cppcheck-suppress unusedFunction
75 void SphinxMatchInfo::setWeightFromDecString(const std::string& weight, unsigned long long length)
76 {
77  unsigned long long value = 0;
78  try
79  {
80  value = std::stoull(weight);
81  }
82  catch(std::exception&)
83  {
84 
85  }
86  setWeightFromNumeric(value, length);
87 }
88 //-------------------------------------------------------------------
90 {
91  if (this != &rhs)
92  {
93  docId = rhs.getDocId();
94  weight = rhs.getWeight();
95  attributes = rhs.getAttributes();
96  }
97  return *this;
98 }
99 //-------------------------------------------------------------------
101 {
102  if (this != &rhs)
103  {
104  docId = std::move(rhs.getDocId());
105  weight = std::move(rhs.getWeight());
106  attributes = std::move(rhs.getAttributes());
107  }
108  return *this;
109 }
110 //-------------------------------------------------------------------
112 {
113  attributes.push_back(SphinxResultDataItem<AttrInfo>(attrInfo));
114 }
115 //-------------------------------------------------------------------
117 {
118  attributes.push_back(SphinxResultDataItem<AttrInfo>(std::forward<AttrInfo>(attrInfo)));
119 }
120 //-------------------------------------------------------------------
121 void SphinxMatchInfo::addAttrInfo(const std::string& name, const std::string& value)
122 {
123  addAttrInfo(std::forward<AttrInfo>(AttrInfo(name, value)));
124 }
125 //-------------------------------------------------------------------
126 const AttrInfo SphinxMatchInfo::getFieldByName(const std::string& attrName) const
127 {
128  AttrInfo attrInfo;
129  for (size_t i=0;i<attributes.size();++i)
130  {
131  if (attributes[i].getItem().name == attrName)
132  {
133  attrInfo = attributes[i].getItem();
134  break;
135  }
136  }
137  return attrInfo;
138 }
139 //-------------------------------------------------------------------
141 {
142  size_t count = attributes.size();
143  for (size_t i=0;i<count;++i)
144  {
145  if (attributes[i].isEmpty())
146  {
147  count = i;
148  break;
149  }
150  }
151  return count;
152 }
153 //-------------------------------------------------------------------
155 {
156  return attributes[index].getItem();
157 }
158 //-------------------------------------------------------------------
159 void SphinxMatchInfo::setAttrItem(size_t index, const AttrInfo& attr)
160 {
161  attributes[index].setItem(attr);
162 }
163 //-------------------------------------------------------------------
165 {
166  attributes[index].setItem(std::forward<AttrInfo>(attr));
167 }
168 //-------------------------------------------------------------------
170 {
171  docId = 0;
172  weight.clear();
173  attributes.clear();
174 }
175 //-------------------------------------------------------------------
177 {
178  docId = 0;
179  weight.clear();
180  const size_t count = attributes.size();
181  for (size_t i=0;i<count;++i)
182  attributes[i].isEmpty(true);
183 }
184 //-------------------------------------------------------------------
186 {
187  attributes.resize(sz);
188  reset();
189 }
190 //-------------------------------------------------------------------
191 //-------------------------------------------------------------------
192 } // namespace sphinx
193 } // namespace HCE