Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

void Impala::Core::Trec::TextSearchConnector::Query ( std::string  q  )  [inline]

Definition at line 52 of file TextSearchConnector.h.

References Impala::atof(), Connect(), Impala::Core::VideoSet::Segmentation::GetShotId(), ILOG_DEBUG, ILOG_ERROR, ILOG_INFO, mConnected, mHasResults, mResults, mSegmentation, mSocket, Impala::Core::Trec::ShotResult::rank, CommunicatingSocket::recv(), Impala::Core::Trec::ShotResult::score, CommunicatingSocket::send(), Impala::Core::Trec::ShotResult::shotid, and tokenize().

00053     {
00054         ILOG_DEBUG("Query: " << q);
00055         mHasResults = false;
00056         if (!mConnected)
00057             Connect();
00058 
00059         if (!mConnected)
00060             return;
00061 
00062         q = q + '\n';
00063 
00064         ILOG_DEBUG("Sending query...");
00065         try {
00066             mSocket->send(q.c_str(), strlen(q.c_str()));
00067         } catch (SocketException e) {
00068             ILOG_ERROR("Server connection failed during SEND.");
00069             mConnected = false;
00070             return;
00071         }
00072         ILOG_DEBUG("query sent.");
00073 
00074         int rem = 0;
00075         char buffer[20000];
00076         for (int i=0; i < 20000; i++) buffer[i]=0;
00077         char *pos = buffer;
00078 
00079         std::vector<std::string> results;
00080         try {
00081             while (true) {
00082                 int beetje = mSocket->recv(pos, 20000 - rem);
00083                 rem += beetje;
00084                 pos = &buffer[rem];
00085                 if (rem >= 20000)
00086                 {
00087                     ILOG_ERROR("Out of buffer memory while retrieving results.");
00088                     return;
00089                 }
00090                 results = tokenize(std::string(buffer));
00091                 // temp bugfix: in Windows the tokenization adds more than just
00092                 // 'DONE'. Since DONE is the only statement ever sent from the
00093                 // text server starting with a D we can also just look for that
00094                 // - Ork
00095                 if (results.size() > 0 && results[results.size()-1][0] == 'D')
00096                 {
00097                     break;
00098                 } 
00099                 if (results.size() > 0 && results[results.size()-1] == "DONE")
00100                 {
00101                     break;
00102                 }
00103             }
00104         } catch (SocketException e) {
00105             ILOG_ERROR("Server connection failed during RECV.");
00106             mConnected = false;
00107             return;
00108         }
00109         results = tokenize(std::string(buffer));
00110         if (results.size() == 1 && results[0] == "DONE")
00111         {
00112             ILOG_INFO("No text results found.");
00113             mHasResults = false;
00114             return;
00115         }
00116 
00117         int found = 0, i=0;
00118         int number = results.size() / 6;
00119         ILOG_DEBUG("Number of results: " << number);
00120 
00121         mResults.clear();
00122         int rank = 1;
00123         while (found < number) {
00124             if (results[i] == "DONE")
00125                 break;
00126             Core::Trec::ShotResult r;
00127             r.shotid = mSegmentation->GetShotId(results[i+2]);
00128             ILOG_DEBUG("Found text result " << rank << " : " << results[i+2] << " score " << results[i+4]);
00129             r.rank = rank++;
00130             r.score = atof(results[i+4]);
00131             mResults.push_back(r);
00132             i+=6;
00133             found++;
00134         }
00135         mHasResults = true;
00136         return;
00137     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:25:55 2010 for ImpalaSrc by  doxygen 1.5.1