HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxResultData.cpp
Go to the documentation of this file.
1 #include <iomanip>
2 #include <sstream>
3 
4 #include "SphinxResultData.hpp"
5 
6 namespace HCE
7 {
8 namespace sphinx
9 {
10 //-----------------------------------------------------------------------------
11 //-----------------------------------------------------------------------------
12 std::ostream& operator << (std::ostream& os, const HexString& rhs)
13 {
14  return os << std::setfill('0') << std::setw(rhs.length) << std::hex << rhs.value;
15 }
16 //-----------------------------------------------------------------------------
17 std::string toHexString(unsigned long long value, unsigned long long length)
18 {
19  std::ostringstream ostr;
20  ostr << HexString(value, length);
21  return ostr.str();
22 }
23 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 :matchInfoList(), requestInfoList()
27 {
28 }
29 //-----------------------------------------------------------------------------
31 :matchInfoList(matchesCount), requestInfoList()
32 {
33  resize(matchesCount);
34 }
35 //-----------------------------------------------------------------------------
37 :matchInfoList(matchesCount), requestInfoList()
38 {
39  resize(matchesCount, attributesCount);
40 }
41 //-----------------------------------------------------------------------------
43 {
44 }
45 //-----------------------------------------------------------------------------
47 {
48  matchInfoList.push_back(SphinxResultDataItem<SphinxMatchInfo>(match));
49 }
50 //-----------------------------------------------------------------------------
52 {
53  matchInfoList.push_back(SphinxResultDataItem<SphinxMatchInfo>(std::forward<SphinxMatchInfo>(match)));
54 }
55 //-----------------------------------------------------------------------------
57 {
58  size_t count = matchInfoList.size();
59  for (size_t i=0;i<count;++i)
60  {
61  if (matchInfoList[i].isEmpty())
62  {
63  count = i;
64  break;
65  }
66  }
67  return count;
68 }
69 //-----------------------------------------------------------------------------
71 {
72  return matchInfoList[index].getItem();
73 }
74 //-----------------------------------------------------------------------------
76 {
77  matchInfoList[index].setItem(match);
78 }
79 //-----------------------------------------------------------------------------
81 {
82  matchInfoList[index].setItem(std::forward<SphinxMatchInfo>(match));
83 }
84 //-----------------------------------------------------------------------------
86 {
87  requestInfoList.push_back(SphinxResultDataItem<SphinxRequestInfo>(request));
88 }
89 //-----------------------------------------------------------------------------
91 {
92  requestInfoList.push_back(SphinxResultDataItem<SphinxRequestInfo>(std::forward<SphinxRequestInfo>(request)));
93 }
94 //-----------------------------------------------------------------------------
96 {
97  size_t count = requestInfoList.size();
98  for (size_t i=0;i<count;++i)
99  {
100  if (requestInfoList[i].isEmpty())
101  {
102  count = i;
103  break;
104  }
105  }
106  return count;
107 }
108 //-----------------------------------------------------------------------------
110 {
111  return requestInfoList[index].getItem();
112 }
113 //-----------------------------------------------------------------------------
114 // cppcheck-suppress unusedFunction
116 {
117  requestInfoList[index].setItem(request);
118 }
119 //-----------------------------------------------------------------------------
121 {
122  requestInfoList[index].setItem(std::forward<SphinxRequestInfo>(request));
123 }
124 //-----------------------------------------------------------------------------
126 {
127  const size_t matchInfoCount = matchInfoList.size();
128  for (size_t i=0;i<matchInfoCount;++i)
129  matchInfoList[i].getItem().clear();
130  matchInfoList.clear();
131 
132  const size_t requestInfoCount = requestInfoList.size();
133  for (size_t i=0;i<requestInfoCount;++i)
134  requestInfoList[i].getItem().clear();
135  requestInfoList.clear();
136 }
137 //-----------------------------------------------------------------------------
139 {
140  const size_t matchInfoCount = matchInfoList.size();
141  for (size_t i=0;i<matchInfoCount;++i)
142  {
143  matchInfoList[i].getItem().reset();
144  matchInfoList[i].isEmpty(true);
145  }
146 
147  const size_t requestInfoCount = requestInfoList.size();
148  for (size_t i=0;i<requestInfoCount;++i)
149  {
150  requestInfoList[i].getItem().reset();
151  requestInfoList[i].isEmpty(true);
152  }
153 }
154 //-----------------------------------------------------------------------------
155 void SphinxResultData::resize(size_t matchesCount)
156 {
157  matchInfoList.resize(matchesCount);
158  reset();
159 }
160 //-----------------------------------------------------------------------------
161 void SphinxResultData::resize(size_t matchesCount, size_t attributesCount)
162 {
163  matchInfoList.resize(matchesCount);
164  for (size_t i=0;i<matchesCount;++i)
165  matchInfoList[i].getItem().resize(attributesCount);
166  reset();
167 }
168 //-------------------------------------------------------------------
170 {
171  requestInfoList.clear();
172 }
173 //-------------------------------------------------------------------
174 void SphinxResultData::dump(std::ostream& os) const
175 {
176  const size_t requestInfoCount = getRequestInfoCount();
177  for (size_t i=0;i<requestInfoCount;++i)
178  {
179  os << "Query stats for '" << getRequestInfoItem(i).getNodeName() << "':\n";
180  const size_t wordsCount = getRequestInfoItem(i).getWordsCount();
181  for (size_t j=0;j<wordsCount;++j)
182  {
183  os << "\t'" << getRequestInfoItem(i).getWordItem(j).word << "' found "
184  << getRequestInfoItem(i).getWordItem(j).hits << " times in "
185  << getRequestInfoItem(i).getWordItem(j).docs << " documents\n";
186  }
187 
188  os << "max: " << getRequestInfoItem(i).getMaxResultsNumber();
189  os << ", order: " << getRequestInfoItem(i).getOrderBy();
190  os << ", q: '" << getRequestInfoItem(i).getQuery() << "'";
191  os << ", qid: " << getRequestInfoItem(i).getQueryId();
192  os << ", r: " << getRequestInfoItem(i).getTotal();
193  os << ", f: " << getRequestInfoItem(i).getTotalFound();
194  os << ", time: " << getRequestInfoItem(i).getTimeMsec() << std::endl;
195  }
196  os << "Matches:\n";
197  const size_t matchInfoCount = getMatchInfoCount();
198  for (size_t i=0;i<matchInfoCount;++i)
199  {
200  os << "\tdocId = " << getMatchInfoItem(i).getDocId() << ", weight = " << getMatchInfoItem(i).getWeight();
201 
203  for (size_t j=0;j<attributesCount;++j)
204  {
205  os << ", " << getMatchInfoItem(i).getAttrItem(j).name << " = " << getMatchInfoItem(i).getAttrItem(j).value;
206  }
207  os << std::endl;
208  }
209  os << std::endl;
210 }
211 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
213 std::ostream& operator << (std::ostream& os, const SphinxResultData& resultData)
214 {
215  resultData.dump(os);
216  return os;
217 }
218 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
220 } // namespace sphinx
221 } // namespace HCE