X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_sparql.cpp;h=638d2bad9000d81a5a71f87f6fa0239b2f94143c;hb=1bd695eb9f4b166b5d32cd5ddac1b1cdf41c14f1;hp=681575a14052137c025c64a7d0eb8023c0331aa6;hpb=c15f541624500e98bcea49b8a77c24d28d4c434d;p=mp-sparql-moved-to-github.git diff --git a/src/filter_sparql.cpp b/src/filter_sparql.cpp index 681575a..638d2ba 100644 --- a/src/filter_sparql.cpp +++ b/src/filter_sparql.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "sparql.h" #include @@ -177,6 +178,32 @@ void yf::SPARQL::configure(const xmlNode *xmlnode, bool test_only, conf->uri = mp::xml::get_text(attr->children); else if (!strcmp((const char *) attr->name, "schema")) conf->schema = mp::xml::get_text(attr->children); + else if (!strcmp((const char *) attr->name, "include")) + { + std::vector dbs; + std::string db = mp::xml::get_text(attr->children); + boost::split(dbs, db, boost::is_any_of(" \t")); + size_t i; + for (i = 0; i < dbs.size(); i++) + { + if (dbs[i].length() == 0) + continue; + std::list::const_iterator it = db_conf.begin(); + while (1) + if (it == db_conf.end()) + { + throw mp::filter::FilterException( + "include db not found: " + dbs[i]); + } + else if (dbs[i].compare((*it)->db) == 0) + { + yaz_sparql_include(s, (*it)->s); + break; + } + else + it++; + } + } else throw mp::filter::FilterException( "Bad attribute " + std::string((const char *) @@ -421,18 +448,19 @@ Z_Records *yf::SPARQL::Session::fetch( std::list::iterator it = fset->results.begin(); const char *schema = 0; bool uri_lookup = false; + bool fetch_logged = false; if (esn && esn->which == Z_ElementSetNames_generic) schema = esn->u.generic; for (; it != fset->results.end(); it++) { - if (schema && !strcmp(esn->u.generic, it->conf->schema.c_str())) - break; if (yaz_sparql_lookup_schema(it->conf->s, schema)) { uri_lookup = true; break; } + if (!schema || !strcmp(esn->u.generic, it->conf->schema.c_str())) + break; } if (it == fset->results.end()) { @@ -479,7 +507,9 @@ Z_Records *yf::SPARQL::Session::fetch( { if (n->type == XML_ELEMENT_NODE) { - if (!strcmp((const char *) n->name, "uri")) + //if (!strcmp((const char *) n->name, "uri")) + if (!strcmp((const char *) n->name, "uri") || + !strcmp((const char *) n->name, "bnode") ) { uri = mp::xml::get_text(n->children); @@ -507,7 +537,19 @@ Z_Records *yf::SPARQL::Session::fetch( uri.c_str(), schema); if (!error) { - yaz_log(YLOG_LOG, "query=%s", query.c_str()); + if (!fetch_logged) + { // Log the fetch query only once + package.log("sparql", YLOG_LOG, + "fetch query: for %s \n%s", + uri.c_str(), query.c_str() ); + fetch_logged = true; + } + else + { + package.log("sparql", YLOG_LOG, + "fetch uri:%s", uri.c_str() ); + } + //yaz_log(YLOG_LOG, "query=%s", query.c_str()); error = invoke_sparql(package, query.c_str(), it->conf, w); } @@ -607,6 +649,9 @@ Z_APDU *yf::SPARQL::Session::search(mp::Package &package, Z_APDU *apdu_res = 0; mp::wrbuf w; + package.log("sparql", YLOG_LOG, + "search query:\n%s", sparql_query ); + int error = invoke_sparql(package, sparql_query, conf, w); if (error) { @@ -766,7 +811,8 @@ void yf::SPARQL::Session::handle_z(mp::Package &package, Z_APDU *apdu_req) fset->db = db; it = m_sparql->db_conf.begin(); for (; it != m_sparql->db_conf.end(); it++) - if (yaz_match_glob((*it)->db.c_str(), db.c_str())) + if ((*it)->schema.length() > 0 + && yaz_match_glob((*it)->db.c_str(), db.c_str())) { mp::wrbuf addinfo_wr; mp::wrbuf sparql_wr;