3 #include <Poco/AutoPtr.h>
4 #include <Poco/String.h>
5 #include <Poco/Logger.h>
23 :
inherited(),
SphinxNodeOptions(nodeName_, 0, homeDir_, indexName_), searcher(*this, startSearchd_, stopSearchd_), indexer(*this),
24 loaded(false), checkIncomingDocuments(false), packIncomingDocuments(false), minNumberFieldsPacking(0),
25 logger(sphinx_search_const::
moduleName), messagesCollection(message_const::
messages), message(messagesCollection),
26 matchMode(SPH_MATCH_EXTENDED2), sortMode(SPH_SORT_RELEVANCE), rankingMode(SPH_RANK_DEFAULT), rankerExpression(
"")
28 if (!homeDir_.empty() && !indexName_.empty())
43 :
inherited(),
SphinxNodeOptions(nodeName_, nodeNumber_, homeDir_, indexName_), searcher(*this, startSearchd_, stopSearchd_), indexer(*this),
44 loaded(false), checkIncomingDocuments(false), packIncomingDocuments(false), minNumberFieldsPacking(0),
45 logger(sphinx_search_const::
moduleName), messagesCollection(message_const::
messages), message(messagesCollection),
46 matchMode(SPH_MATCH_EXTENDED2), sortMode(SPH_SORT_RELEVANCE), rankingMode(SPH_RANK_DEFAULT), rankerExpression(
"")
48 if (!homeDir_.empty() && !indexName_.empty())
81 return logger.
logMsg(isReset);
86 return logger.
log(logPriority);
101 size_t pos = in.find(
':');
102 if (pos==std::string::npos)
105 outPort = std::stoul(Poco::trim(in));
109 outHost = Poco::trim(std::string(in, 0, pos));
110 outPort = std::stoul(Poco::trim(std::string(in, pos+1)));
116 rankingMode=rankingMode_;
117 if (!rankerExpression_.empty())
118 rankerExpression = rankerExpression_;
140 unsigned int port = 0;
148 std::ifstream ifs(file.c_str());
152 std::vector<std::pair<std::string, int> > weights;
159 ifs.open(file.c_str());
164 std::vector<std::string> schemaNames;
165 loaded = schema.
getNames(schemaNames);
184 std::vector<std::string> keys;
187 for (
size_t i = 0;i<keys.size();++i)
190 if (found!=std::string::npos)
193 if (found!=std::string::npos)
195 weights.push_back(std::make_pair(keys[i].substr(found), 1));
205 catch(Poco::Exception& e)
210 catch(std::exception& e)
225 return searcher.
easyStart(matchMode, sortMode, rankingMode, rankerExpression);
253 return searcher.
open();
258 return searcher.
close();
365 std::string resultData;
366 timeval tvStart, tvStop;
367 gettimeofday(&tvStart, 0);
368 bool needDefaultJson =
false;
372 if (inputJsonMessage.
isError())
375 if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtSearch)
377 needDefaultJson =
true;
379 if (resultData.empty())
382 else if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtIndex)
386 else if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtManage)
394 catch(Poco::Exception& e)
399 Poco::Logger::root().log(e);
401 catch(std::exception& e)
406 Poco::Logger::root().error(e.what());
410 gettimeofday(&tvStop, 0);
415 outputMessage.
setData(resultData);
432 std::string resultData;
433 timeval tvStart, tvStop;
434 gettimeofday(&tvStart, 0);
435 bool needDefaultJson =
false;
438 if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtSearch)
440 needDefaultJson =
true;
442 if (resultData.empty())
445 else if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtIndex)
449 else if (inputJsonMessage.
getType() == SphinxInputJsonMessage::MessageType::mtManage)
456 catch(Poco::Exception& e)
461 Poco::Logger::root().log(e);
463 catch(std::exception& e)
468 Poco::Logger::root().error(e.what());
471 gettimeofday(&tvStop, 0);
476 outputMessage.
setData(resultData);
479 return outputMessage;
482 std::string SphinxFunctionalObject::makeDefaultJSON(
const std::string& logMsg)
491 std::string resultMessageBody;
494 if ((inputJsonMessage.
getType() == HCE::sphinx::SphinxInputJsonMessage::MessageType::mtSearch) && !inputJsonMessage.
isError())
498 for (
size_t k=0;k<messageSearch.getQueryParameters().size();++k)
502 std::istringstream(messageSearch.getQueryParameters()[k].second) >> queryId;
511 resultData.
addRequestInfo(std::forward<HCE::sphinx::SphinxRequestInfo>(requestInfo));
514 if (resultSerializator.
serialize(resultMessageBody))
515 outputJsonMessage.
setData(resultMessageBody);
522 if (!outputJsonMessage.
serialize(resultMessageBody))
524 std::stringstream errMsg;
528 return resultMessageBody;