22 const std::string inputJson =
"{\"data\":\"{\\\"parameters\\\":[{\\\"queryId\\\":\\\"777\\\"},{\\\"JsonType\\\":\\\"7\\\"}],\\\"q\\\":\\\"test\\\"}\",\"type\":0}";
31 std::cout <<
"Input json type = " << (
unsigned int)(inputMsg.
getType()) <<
std::endl;
34 assert(inputMsg.
getType()==HCE::sphinx::SphinxInputJsonMessage::MessageType::mtSearch);
35 assert(!inputMsg.
getData().empty());
38 assert(!messageSearch.isError());
41 std::cout <<
"Parameters count = " << messageSearch.getQueryParameters().size() <<
std::endl;
43 assert(messageSearch.getQueryString()==
"test");
44 assert(messageSearch.getQueryParameters().size()==2);
46 for (
size_t i=0;i<messageSearch.getQueryParameters().size();++i)
48 if (messageSearch.getQueryParameters()[i].first==
"queryId")
49 assert(messageSearch.getQueryParameters()[i].second==
"777");
51 if (messageSearch.getQueryParameters()[i].first==
"JsonType")
52 assert(messageSearch.getQueryParameters()[i].second==
"7");
53 std::cout <<
"Parameter name: '" << messageSearch.getQueryParameters()[i].first <<
"' value: '" << messageSearch.getQueryParameters()[i].second <<
"'" <<
std::endl;
64 inputMsg.
setType(HCE::sphinx::SphinxInputJsonMessage::MessageType::mtSearch);
67 std::stringstream str;
70 std::cout <<
" input json: '" << inputJson <<
"'\n";
71 std::cout <<
"output json: '" << str.str() <<
"'\n";
72 assert(str.str()==inputJson);
73 std::cout <<
"testInputJsonMessage - OK" <<
std::endl;
82 const std::string inputJson =
"{\"data\":\"U29tZSBjb250ZW50IG9mIGRhdGE=\",\"error_code\":2000,\"error_message\":\"Some error\",\"time\":23}";
88 assert(!outputMessage.
isError());
98 std::cout <<
"outputMessage.getData(): '" << outputMessage.
getData() <<
"'" <<
std::endl;
100 assert(outputMessage.
getData()==
"Some content of data");
101 assert(outputMessage.
getTime()==23);
104 outputMessage.
clear();
107 outputMessage.
setData(
"Some content of data");
110 std::string outputJson;
111 assert(outputMessage.
serialize(outputJson));
112 assert(!outputMessage.
isError());
114 std::cout <<
" input json: '" << inputJson <<
"'\n";
115 std::cout <<
"output json: '" << outputJson <<
"'\n";
116 assert(inputJson==outputJson);
117 std::cout <<
"testOutputJsonMessage - OK" <<
std::endl;
124 const std::string
nodeName =
"test_node";
125 const std::string
homeDir =
"/home/alexander/.local/share/hce";
133 std::cout <<
"LOAD CONFIG => " << std::boolalpha << fObj.
isLoadedConfig() <<
"\tIS ERROR => " << std::boolalpha << fObj.
isError()
136 const std::string
query =
"apple";
168 handler.
setType(HCE::sphinx::SphinxInputJsonMessage::MessageType::mtSearch);
169 handler.setData(json);
171 std::stringstream str;
184 assert(!outputMessage.
isError());
188 std::cout <<
"Result:\n" << Result <<
std::endl;
191 const size_t matchInfoCount = Result.getMatchInfoCount();
192 for (
size_t i=0;i<matchInfoCount;++i)
194 unsigned long long docId = Result.getMatchInfoItem(i).getDocId();
195 std::string
weight = Result.getMatchInfoItem(i).getWeight();
197 std::cout <<
"docId: " << docId <<
" weight: " << weight <<
std::endl;
199 const size_t attributesCount = Result.getMatchInfoItem(i).getAttributesCount();
202 std::cout << Result.getMatchInfoItem(i).getAttrItem(j).name <<
" = " << Result.getMatchInfoItem(i).getAttrItem(j).value <<
std::endl;
206 const size_t requestInfoCount = Result.getRequestInfoCount();
207 for (
size_t i=0;i<requestInfoCount;++i)
209 std::cout <<
"nodeName: " << Result.getRequestInfoItem(i).getNodeName() <<
std::endl;
210 std::cout <<
"query: " << Result.getRequestInfoItem(i).getQuery() <<
std::endl;
211 std::cout <<
"queryId: " << Result.getRequestInfoItem(i).getQueryId() <<
std::endl;
212 std::cout <<
"maxResultsNumber: " << Result.getRequestInfoItem(i).getMaxResultsNumber() <<
std::endl;
213 std::cout <<
"orderBy: " << Result.getRequestInfoItem(i).getOrderBy() <<
std::endl;
214 std::cout <<
"total: " << Result.getRequestInfoItem(i).getTotal() <<
std::endl;
215 std::cout <<
"totalFound: " << Result.getRequestInfoItem(i).getTotalFound() <<
std::endl;
216 std::cout <<
"timeMsec: " << Result.getRequestInfoItem(i).getTimeMsec() <<
std::endl;
218 const size_t wordsCount = Result.getRequestInfoItem(i).getWordsCount();
219 for (
size_t j=0;j<wordsCount;++j)
221 std::cout <<
"word: " << Result.getRequestInfoItem(i).getWordItem(j).word
222 <<
", hits: " << Result.getRequestInfoItem(i).getWordItem(j).hits
223 <<
", docs: " << Result.getRequestInfoItem(i).getWordItem(j).docs <<
std::endl;
232 const std::string
nodeName =
"test_node";
233 const std::string
dataDir =
"/var/lib/hce_cluster";
236 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"Create object...\n";
237 std::cout <<
"Log test:\n";
238 std::cout <<
"--------------------------\n" << fObj.
logMsg(
false) <<
std::endl;
239 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"Write some text...\n";
240 std::cout <<
"--------------------------\n" << fObj.
logMsg() <<
std::endl;
243 std::ofstream ofs(
"./out.log", std::fstream::trunc);
246 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"first line to cout...\n";
247 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"second line to cout...\n";
248 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"three line to cout...\n";
251 fObj.
log(HCE::LoggerStream::Priority::PRIO_INFORMATION) <<
"Added some text...\n";
253 std::cout <<
"--------------------------\n" << fObj.
logMsg() <<
std::endl;