X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Frpn2solr.c;h=1a392043c7c18926d042866babf19643bb03723b;hp=5894abef2f07aadb6ef0d96e6cd031d565889b72;hb=8cb8947e3a7bff4dbf8f124871cb4905df1adce7;hpb=473824797f568578dc17d7242551cb2f7ccef46c diff --git a/src/rpn2solr.c b/src/rpn2solr.c index 5894abe..1a39204 100644 --- a/src/rpn2solr.c +++ b/src/rpn2solr.c @@ -19,11 +19,6 @@ #include #include -static void wrbuf_vputs(const char *buf, void *client_data) -{ - wrbuf_write((WRBUF) client_data, buf, strlen(buf)); -} - static const char *lookup_index_from_string_attr(Z_AttributeList *attributes) { int j; @@ -158,15 +153,11 @@ static int rpn2solr_attr(solr_transform_t ct, const char *index = solr_lookup_reverse(ct, "index.", attributes); const char *structure = solr_lookup_reverse(ct, "structure.", attributes); - /* if transform (properties) do not match, we'll just use a USE string attribute (bug #2978) */ + /* if no real match, try string attribute */ if (!index) index = lookup_index_from_string_attr(attributes); if (!index) - { - solr_transform_set_error(ct, - YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0); - return -1; - } + return YAZ_BIB1_UNSUPP_USE_ATTRIBUTE; /* for serverChoice we omit index+relation+structure */ if (strcmp(index, "cql.serverChoice")) { @@ -229,8 +220,7 @@ static int emit_term(solr_transform_t ct, WRBUF w, Z_Term *term, Odr_int trunc) lterm = strlen(sterm); break; default: - solr_transform_set_error(ct, YAZ_BIB1_TERM_TYPE_UNSUPP, 0); - return -1; + return YAZ_BIB1_TERM_TYPE_UNSUPP; } if (sterm) @@ -238,11 +228,18 @@ static int emit_term(solr_transform_t ct, WRBUF w, Z_Term *term, Odr_int trunc) size_t i; int must_quote = 0; - for (i = 0 ; i < lterm; i++) - if (sterm[i] == ' ') - must_quote = 1; + if (lterm == 0) + must_quote = 1; + else + { + for (i = 0 ; i < lterm; i++) + if (sterm[i] == ' ') + must_quote = 1; + } if (must_quote) wrbuf_puts(w, "\""); + if (trunc == 2 || trunc == 3) + wrbuf_puts(w, "*"); for (i = 0 ; i < lterm; i++) { if (sterm[i] == '\\' && i < lterm - 1) @@ -268,7 +265,7 @@ static int emit_term(solr_transform_t ct, WRBUF w, Z_Term *term, Odr_int trunc) else wrbuf_putc(w, sterm[i]); } - if (trunc == 1) + if (trunc == 1 || trunc == 3) wrbuf_puts(w, "*"); if (must_quote) wrbuf_puts(w, "\""); @@ -293,8 +290,7 @@ static int rpn2solr_simple(solr_transform_t ct, relation1 = lookup_relation_index_from_attr(apt->attributes); if (!relation1) { - solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 0); - return -1; + return YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; } if (apt2) { @@ -307,12 +303,11 @@ static int rpn2solr_simple(solr_transform_t ct, ret = rpn2solr_attr(ct, apt->attributes, w); if (ret) return ret; - if (trunc == 0 || trunc == 1 || trunc == 100 || trunc == 104) + if ((trunc >= 0 && trunc <= 3) || trunc == 100 || trunc == 104) ; else { - solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE, 0); - return -1; + return YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE; } if (!relation1) @@ -356,18 +351,14 @@ static int rpn2solr_simple(solr_transform_t ct, static int rpn2solr_structure(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), - void *client_data, + void *client_data, Z_RPNStructure *q, int nested, WRBUF w) { if (q->which == Z_RPNStructure_simple) { if (q->u.simple->which != Z_Operand_APT) - { - solr_transform_set_error( - ct, YAZ_BIB1_RESULT_SET_UNSUPP_AS_A_SEARCH_TERM, 0); - return -1; - } + return YAZ_BIB1_RESULT_SET_UNSUPP_AS_A_SEARCH_TERM; else return rpn2solr_simple(ct, pr, client_data, q->u.simple->u.attributesPlusTerm, w, 0); @@ -386,20 +377,19 @@ static int rpn2solr_structure(solr_transform_t ct, r = rpn2solr_structure(ct, pr, client_data, q->u.complex->s1, 1, w); if (r) return r; - switch(op->which) + switch (op->which) { - case Z_Operator_and: + case Z_Operator_and: pr(" AND ", client_data); break; - case Z_Operator_or: + case Z_Operator_or: pr(" OR ", client_data); break; - case Z_Operator_and_not: + case Z_Operator_and_not: pr(" AND NOT ", client_data); break; - case Z_Operator_prox: - solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_SEARCH, 0); - return -1; + case Z_Operator_prox: + return YAZ_BIB1_UNSUPP_SEARCH; } r = rpn2solr_structure(ct, pr, client_data, q->u.complex->s2, 1, w); if (nested) @@ -408,25 +398,37 @@ static int rpn2solr_structure(solr_transform_t ct, } } +int solr_transform_rpn2solr_stream_r(solr_transform_t ct, + WRBUF addinfo, + void (*pr)(const char *buf, void *client_data), + void *client_data, + Z_RPNQuery *q) +{ + int r = rpn2solr_structure(ct, pr, client_data, q->RPNStructure, + /* nested*/ 0, addinfo); + if (!r) + wrbuf_rewind(addinfo); + return r; +} + int solr_transform_rpn2solr_stream(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), void *client_data, Z_RPNQuery *q) { - int r; WRBUF w = wrbuf_alloc(); - solr_transform_set_error(ct, 0, 0); - r = rpn2solr_structure(ct, pr, client_data, q->RPNStructure, 0, w); + int r = solr_transform_rpn2solr_stream_r(ct, w, pr, client_data, q); + if (r) + solr_transform_set_error(ct, r, wrbuf_len(w) ? wrbuf_cstr(w) : 0); wrbuf_destroy(w); return r; } - int solr_transform_rpn2solr_wrbuf(solr_transform_t ct, WRBUF w, Z_RPNQuery *q) { - return solr_transform_rpn2solr_stream(ct, wrbuf_vputs, w, q); + return solr_transform_rpn2solr_stream(ct, wrbuf_vp_puts, w, q); } /*