7 namespace reduce_task {
18 Poco::SharedPtr<SphinxReduceDataStorage> &sphinxDataStorage,
19 const Poco::SharedPtr<HCE::reduce::core::ReduceResultIf> &sphinxReduceResult,
23 fillMatchInfo(sphinxDataStorage, sphinxReduceResult, newSphinxResult);
24 fillRequestInfo(requestInfo, newSphinxResult);
25 return newSphinxResult;
29 const Poco::SharedPtr<SphinxResultData> &sphinxResultData,
30 std::vector<std::pair<std::string, unsigned long long> > &selectWeightKeys)
33 fillMatchDataBaseOnKeys(sphinxResultData, selectWeightKeys, newSphinxResult);
34 fillRequestInfoBaseOnResultData(sphinxResultData, newSphinxResult);
35 return newSphinxResult;
38 void SphinxResultBuilder::fillMatchInfo(
39 Poco::SharedPtr<SphinxReduceDataStorage> &sphinxDataStorage,
40 Poco::SharedPtr<HCE::reduce::core::ReduceResultIf> sphinxReduceResult,
41 Poco::SharedPtr<SphinxResultData>& newSphinxResultData)
44 std::string value =
"";
47 sphinxReduceResult->reset();
48 while(sphinxReduceResult->hasNext()){
49 sphinxReduceResult->getNext(key, value);
50 matchInfoIter = sphinxDataStorage->getData(key + value);
51 if (matchInfoIter.first == matchInfoIter.second){
54 newSphinxResultData->addMatchInfo(matchInfoIter.first->second);
58 void SphinxResultBuilder::fillRequestInfo(
60 Poco::SharedPtr<SphinxResultData>& newSphinxResultData)
62 for (
size_t infoIndex = 0; infoIndex < requestInfo.size(); ++infoIndex){
63 newSphinxResultData->addRequestInfo(requestInfo[infoIndex]);
67 void SphinxResultBuilder::fillMatchDataBaseOnKeys(
68 const Poco::SharedPtr<SphinxResultData> &sphinxResultData,
69 std::vector<std::pair<std::string, unsigned long long> > &selectWeightKeys,
70 Poco::SharedPtr<SphinxResultData> &newSphinxResult)
72 std::map<unsigned long long, SphinxMatchInfo> keysMatchInfo;
73 std::map<unsigned long long, SphinxMatchInfo>::iterator bestMatchInfoIt;
75 buildMatchInfoMap(keysMatchInfo, sphinxResultData);
77 for (
size_t matchIndex = 0; matchIndex < selectWeightKeys.size(); ++matchIndex){
78 bestMatchInfoIt = keysMatchInfo.find(selectWeightKeys[matchIndex].second);
79 if (bestMatchInfoIt != keysMatchInfo.end()){
80 newSphinxResult->addMatchInfo(bestMatchInfoIt->second);
85 void SphinxResultBuilder::fillRequestInfoBaseOnResultData(
86 const Poco::SharedPtr<SphinxResultData> &sphinxResultData,
87 Poco::SharedPtr<SphinxResultData> &newSphinxResult)
89 size_t totalRequestInfoNumber = sphinxResultData->getRequestInfoCount();
90 for (
size_t requestInfoIndex = 0; requestInfoIndex < totalRequestInfoNumber;
92 newSphinxResult->addRequestInfo(sphinxResultData->getRequestInfoItem(requestInfoIndex));
96 void SphinxResultBuilder::buildMatchInfoMap(std::map<unsigned long long, SphinxMatchInfo> &keysMatchInfo,
97 const Poco::SharedPtr<SphinxResultData> &sphinxResultData)
99 size_t totalMatchInfoNumber = sphinxResultData->getMatchInfoCount();
100 for(
size_t keyIndex = 0; keyIndex < totalMatchInfoNumber; ++keyIndex){
101 SphinxMatchInfo
matchInfo = sphinxResultData->getMatchInfoItem(keyIndex);
102 keysMatchInfo.insert(std::make_pair(matchInfo.getDocId(),
matchInfo));