From: Heikki Levanto Date: Wed, 20 May 2015 13:47:56 +0000 (+0200) Subject: MPSPARQL-22: Allow simple searching in the info records X-Git-Tag: v0.6~9 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=073e1576bdafa9aa161ab544356f7b763414673d;p=mp-sparql-moved-to-github.git MPSPARQL-22: Allow simple searching in the info records Always takes the last term in the query, ignoring all attributes and operators. If the query is an empty string, or starts with something non-alphabetic, will return info on all bases. Otherwise on the matching base only. --- diff --git a/src/filter_sparql.cpp b/src/filter_sparql.cpp index 8cf720a..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 @@ -709,24 +710,32 @@ 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() ); @@ -775,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, @@ -982,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");