X-Git-Url: http://git.indexdata.com/?p=mp-sparql-moved-to-github.git;a=blobdiff_plain;f=src%2Fsparql.c;h=6fe5e5c6b9741dab2ccfed04f78e761038fce5ed;hp=0ce6c405f40464d603436e3b0a8cc7db13f5111f;hb=e625c126cea3e3e11aaa8d40b03237d9b22b6525;hpb=c67fb311da29c5b98eeb003ca1c07c1274fea947 diff --git a/src/sparql.c b/src/sparql.c index 0ce6c40..6fe5e5c 100644 --- a/src/sparql.c +++ b/src/sparql.c @@ -37,6 +37,13 @@ void yaz_sparql_destroy(yaz_sparql_t s) nmem_destroy(s->nmem); } +void yaz_sparql_include(yaz_sparql_t s, yaz_sparql_t u) +{ + struct sparql_entry *e = u->conf; + for (; e; e = e->next) + yaz_sparql_add_pattern(s, e->pattern, e->value); +} + int yaz_sparql_add_pattern(yaz_sparql_t s, const char *pattern, const char *value) { @@ -158,6 +165,21 @@ static int z_term(yaz_sparql_t s, WRBUF addinfo, WRBUF res, WRBUF vars, } wrbuf_puts(addinfo, ">"); break; + case 't': + switch (term->which) + { + case Z_Term_general: + wrbuf_json_write(addinfo, + term->u.general->buf, term->u.general->len); + break; + case Z_Term_numeric: + wrbuf_printf(addinfo, ODR_INT_PRINTF, *term->u.numeric); + break; + case Z_Term_characterString: + wrbuf_json_puts(addinfo, term->u.characterString); + break; + } + break; case 'd': switch (term->which) { @@ -359,6 +381,10 @@ static int emit_prefixes(yaz_sparql_t s, { ; } + else if (!strncmp(e->pattern, "present", 7)) + { + ; + } else if (!strncmp(e->pattern, "uri", 3)) { ; @@ -378,6 +404,11 @@ struct sparql_entry *lookup_schema(yaz_sparql_t s, const char *schema) for (e = s->conf; e; e = e->next) { + if (!strncmp(e->pattern, "present.", 8)) + { + if (!schema || !strcmp(e->pattern + 8, schema)) + break; + } if (!strncmp(e->pattern, "uri.", 4)) { if (!schema || !strcmp(e->pattern + 4, schema)) @@ -509,6 +540,48 @@ int yaz_sparql_from_rpn_stream(yaz_sparql_t s, return errors ? -1 : r; } +void yaz_sparql_explain_indexes( yaz_sparql_t s, WRBUF w, int indent) +{ + char indentspace[200]; // must be enough + assert(indent<200); + int i; + for (i=0; i < indent; i++) + indentspace[i] = ' '; + indentspace[indent] = '\0'; + + struct sparql_entry *e; + wrbuf_puts(w,indentspace); + wrbuf_puts(w,"\n"); + + for (e = s->conf; e; e = e->next) + { + /* + wrbuf_puts(w," "); + wrbuf_xmlputs(w, e->pattern ); + wrbuf_puts(w," : "); + wrbuf_xmlputs(w, e->value ); + wrbuf_puts(w," \n"); + */ + if ( strncmp(e->pattern, "index.", 6 ) == 0 ) + { + wrbuf_puts(w,indentspace); + wrbuf_puts(w," \n"); + wrbuf_puts(w,indentspace); + wrbuf_puts(w," "); + wrbuf_xmlputs(w, e->pattern + 6); + wrbuf_puts(w,"\n"); + wrbuf_puts(w,indentspace); + wrbuf_puts(w," "); + wrbuf_xmlputs(w, e->pattern + 6); + wrbuf_puts(w,"\n"); + wrbuf_puts(w,indentspace); + wrbuf_puts(w," \n"); + } + } + wrbuf_puts(w,indentspace); + wrbuf_puts(w,"\n"); +} + /* * Local variables: * c-basic-offset: 4