00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INDRI_QUERYRESPONSEPACKER_HPP
00020 #define INDRI_QUERYRESPONSEPACKER_HPP
00021
00022 #include "indri/InferenceNetwork.hpp"
00023 #include "lemur-compat.hpp"
00024 namespace indri
00025 {
00026 namespace net
00027 {
00028
00029 class QueryResponsePacker {
00030 private:
00031 indri::infnet::InferenceNetwork::MAllResults& _results;
00032
00033 public:
00034 QueryResponsePacker( indri::infnet::InferenceNetwork::MAllResults& results ) :
00035 _results(results)
00036 {
00037 }
00038
00039 void write( NetworkMessageStream* stream ) {
00040 indri::infnet::InferenceNetwork::MAllResults::iterator iter;
00041 indri::infnet::EvaluatorNode::MResults::iterator nodeIter;
00042
00043 for( iter = _results.begin(); iter != _results.end(); iter++ ) {
00044 const std::string& nodeName = iter->first;
00045
00046 for( nodeIter = iter->second.begin(); nodeIter != iter->second.end(); nodeIter++ ) {
00047 const std::string& listName = nodeIter->first;
00048 std::string resultName = nodeName + ":" + listName;
00049 const std::vector<indri::api::ScoredExtentResult>& resultList = nodeIter->second;
00050
00051
00052
00053 const char resultSize=(sizeof(INT32)*5 + sizeof(double) + sizeof(INT64));
00054 char networkResults[resultSize * 100];
00055 size_t resultsSent = 0;
00056
00057 while( resultList.size() > resultsSent ) {
00058 size_t sendChunk = lemur_compat::min<size_t>( resultList.size() - resultsSent, (size_t) 100 );
00059
00060 for( size_t i=0; i<sendChunk; i++ ) {
00061 indri::api::ScoredExtentResult byteSwapped;
00062 const indri::api::ScoredExtentResult& unswapped = resultList[i + resultsSent];
00063
00064 byteSwapped.begin = htonl(unswapped.begin);
00065 byteSwapped.end = htonl(unswapped.end);
00066 byteSwapped.document = htonl(unswapped.document );
00067 byteSwapped.score = lemur_compat::htond(unswapped.score);
00068 byteSwapped.number = lemur_compat::htonll(unswapped.number);
00069 byteSwapped.ordinal = htonl(unswapped.ordinal);
00070 byteSwapped.parentOrdinal = htonl(unswapped.parentOrdinal);
00071
00072 memcpy( networkResults + i*resultSize, &byteSwapped.score, sizeof(double) );
00073 memcpy( networkResults + i*resultSize + 8, &byteSwapped.document, sizeof(INT32) );
00074 memcpy( networkResults + i*resultSize + 12, &byteSwapped.begin, sizeof(INT32) );
00075 memcpy( networkResults + i*resultSize + 16, &byteSwapped.end, sizeof(INT32) );
00076 memcpy( networkResults + i*resultSize + 20, &byteSwapped.number, sizeof(INT64) );
00077 memcpy( networkResults + i*resultSize + 28, &byteSwapped.ordinal, sizeof(INT32) );
00078 memcpy( networkResults + i*resultSize + 32, &byteSwapped.parentOrdinal, sizeof(INT32) );
00079 }
00080
00081 stream->reply( resultName, networkResults, int(sendChunk * resultSize) );
00082 resultsSent += sendChunk;
00083 }
00084 }
00085 }
00086
00087 stream->replyDone();
00088 }
00089 };
00090 }
00091 }
00092
00093 #endif // INDRI_QUERYRESPONSEPACKER_HPP
00094