X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Frpn2solr.c;h=332ae88c9d09d7fbc4c6581c922d3538b7ad03bf;hp=800684765e158f5895bc85e1ccbd3208f4b83e37;hb=31b5ce78766f1731a376e2f5e11f530261434345;hpb=f50e88ece40cd62eb9e969cd138e3f274725a991 diff --git a/src/rpn2solr.c b/src/rpn2solr.c index 8006847..332ae88 100644 --- a/src/rpn2solr.c +++ b/src/rpn2solr.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** @@ -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,9 +220,9 @@ 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) { size_t i; @@ -242,6 +233,8 @@ static int emit_term(solr_transform_t ct, WRBUF w, Z_Term *term, Odr_int trunc) 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) @@ -267,7 +260,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, "\""); @@ -292,8 +285,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) { @@ -306,12 +298,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) @@ -355,18 +346,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); @@ -385,20 +372,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) @@ -414,8 +400,9 @@ int solr_transform_rpn2solr_stream(solr_transform_t ct, { int r; WRBUF w = wrbuf_alloc(); - solr_transform_set_error(ct, 0, 0); r = rpn2solr_structure(ct, pr, client_data, q->RPNStructure, 0, w); + if (r) + solr_transform_set_error(ct, r, 0); wrbuf_destroy(w); return r; } @@ -425,7 +412,7 @@ 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); } /*