X-Git-Url: http://git.indexdata.com/?p=mp-sparql-moved-to-github.git;a=blobdiff_plain;f=src%2Ffilter_sparql.cpp;h=a38567d0f83b5eeab93dce04abd3bfe409a44e2d;hp=2ff3cf4195d2483152485c9f4f9e75a8fcd24f4d;hb=e625c126cea3e3e11aaa8d40b03237d9b22b6525;hpb=dc40821899058dd61bf0a18ef16ec136d689c156 diff --git a/src/filter_sparql.cpp b/src/filter_sparql.cpp index 2ff3cf4..a38567d 100644 --- a/src/filter_sparql.cpp +++ b/src/filter_sparql.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include #include @@ -673,18 +674,19 @@ Z_Records *yf::SPARQL::Session::explain_fetch( int i; for (i = 0; i < number; i++) { - int idx = start + i - 1; - ConfPtr cp = fset->explaindblist[ idx]; - package.log("sparql", YLOG_LOG, "fetch explain %d:%s", idx, cp->db.c_str() ); + unsigned int idx = start + i - 1; + if ( idx >= fset->explaindblist.size() ) + break; + ConfPtr cp = fset->explaindblist[idx]; mp::wrbuf w; - wrbuf_puts(w,"\n"); + wrbuf_puts(w,"\n"); wrbuf_puts(w," \n"); wrbuf_puts(w," "); wrbuf_xmlputs(w, cp->db.c_str()); wrbuf_puts(w,"\n"); wrbuf_puts(w," \n"); yaz_sparql_explain_indexes( cp->s, w, 2); - wrbuf_puts(w,"\n"); + wrbuf_puts(w,"\n"); rec->u.databaseOrSurDiagnostics->records[i] = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(Z_NamePlusRecord)); @@ -696,7 +698,7 @@ Z_Records *yf::SPARQL::Session::explain_fetch( } rec->u.databaseOrSurDiagnostics->num_records = i; *number_returned = i; - if (start + number > fset->hits) + if (start + number > (int)fset->explaindblist.size()) *next_position = 0; else *next_position = start + number; @@ -708,42 +710,36 @@ Z_Records *yf::SPARQL::Session::explain_fetch( Z_APDU *yf::SPARQL::Session::explain_search(mp::Package &package, Z_APDU *apdu_req, mp::odr &odr, - const char *sparql_query, + const char *explain_query, FrontendSetPtr fset) { Z_SearchRequest *req = apdu_req->u.searchRequest; Z_APDU *apdu_res = 0; //mp::wrbuf w; - package.log("sparql", YLOG_LOG, "Explain search" ); + package.log("sparql", YLOG_LOG, "Explain search '%s'", explain_query ); + const char *term = explain_query + strlen(explain_query); + while ( term > explain_query && *term != ' ') + term--; + term++; + if ( ! isalpha( *term) ) + term=""; // anything non-alpha is taken to mean all + // Empty string is seen here as two double quotes "" + // so it returns all bases as well int numbases = 0; - //std::list dblist; std::list::const_iterator it = m_sparql->db_conf.begin(); m_frontend_sets[req->resultSetName] = fset; fset->explaindblist.clear(); fset->explaindblist.reserve(m_sparql->db_conf.size()); for (; it != m_sparql->db_conf.end(); it++) - if ((*it)->schema.length() > 0 ) // searchable db - { + if ( (*it)->schema.length() > 0 && // searchable db + (!*term || strcmp(term,(*it)->db.c_str())==0) ) + { // and want all, or found the matching one numbases++; package.log("sparql", YLOG_LOG, "Explain %d: '%s'", numbases, (*it)->db.c_str() ); fset->explaindblist.push_back(*it); -/* - //yf::SPARQL::Result res; - //res.conf = *it; - std::string z = - "" - "" - "" + - (*it)->db + - "" - "" - ""; - //res.doc = xmlParseMemory(z.c_str(), z.size()); - dblist.push_back(z); -*/ } int number_returned = 0; int next_position = 0; @@ -788,6 +784,7 @@ Z_APDU *yf::SPARQL::Session::explain_search(mp::Package &package, return apdu_res; } + Z_APDU *yf::SPARQL::Session::search(mp::Package &package, Z_APDU *apdu_req, mp::odr &odr, @@ -958,7 +955,7 @@ void yf::SPARQL::Session::handle_z(mp::Package &package, Z_APDU *apdu_req) m_frontend_sets.erase(req->resultSetName); fset->db = db; - if ( db != "explain" ) + if ( db != "info" ) { it = m_sparql->db_conf.begin(); for (; it != m_sparql->db_conf.end(); it++) @@ -995,9 +992,10 @@ void yf::SPARQL::Session::handle_z(mp::Package &package, Z_APDU *apdu_req) else { // The magic "explain" base yaz_log(YLOG_LOG,"About to call explain_search"); - const char *qry = "query"; + mp::wrbuf qry; + yaz_query_to_wrbuf(qry, req->query); apdu_res = explain_search( package, apdu_req, odr, - qry, fset); + qry.c_str(), fset); // TODO - Extract at least a term from the query, and // do some filtering by that yaz_log(YLOG_LOG,"Returned from explain_search");