int solr_transform_rpn2solr_stream(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), void *client_data, Z_RPNQuery *q) { WRBUF w = wrbuf_alloc(); 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_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); wrbuf_destroy(w); return r; }
static int rpn2solr_structure(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), void *client_data, Z_RPNStructure *q, int nested, WRBUF w) { if (q->which == Z_RPNStructure_simple) return rpn2solr_simple(ct, pr, client_data, q->u.simple, w); else { Z_Operator *op = q->u.complex->roperator; int r; if (nested) pr("(", client_data); r = rpn2solr_structure(ct, pr, client_data, q->u.complex->s1, 1, w); if (r) return r; switch(op->which) { case Z_Operator_and: pr(" AND ", client_data); break; case Z_Operator_or: pr(" OR ", client_data); break; 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; } r = rpn2solr_structure(ct, pr, client_data, q->u.complex->s2, 1, w); if (nested) pr(")", client_data); return r; } }
static int rpn2solr_simple(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), void *client_data, Z_Operand *q, WRBUF w) { int ret = 0; if (q->which != Z_Operand_APT) { ret = -1; solr_transform_set_error(ct, YAZ_BIB1_RESULT_SET_UNSUPP_AS_A_SEARCH_TERM, 0); } else { Z_AttributesPlusTerm *apt = q->u.attributesPlusTerm; Z_Term *term = apt->term; const char *sterm = 0; size_t lterm = 0; Odr_int trunc = get_truncation(apt); wrbuf_rewind(w); ret = rpn2solr_attr(ct, apt->attributes, w); if (trunc == 0 || trunc == 1 || trunc == 100 || trunc == 104) ; else { solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE, 0); return -1; } switch (term->which) { case Z_Term_general: lterm = term->u.general->len; sterm = (const char *) term->u.general->buf; break; case Z_Term_numeric: wrbuf_printf(w, ODR_INT_PRINTF, *term->u.numeric); break; case Z_Term_characterString: sterm = term->u.characterString; lterm = strlen(sterm); break; default: ret = -1; solr_transform_set_error(ct, YAZ_BIB1_TERM_TYPE_UNSUPP, 0); } if (sterm) { size_t i; int must_quote = 0; for (i = 0 ; i < lterm; i++) if (sterm[i] == ' ') must_quote = 1; if (must_quote) wrbuf_puts(w, "\""); for (i = 0 ; i < lterm; i++) { if (sterm[i] == '\\' && i < lterm - 1) { i++; if (strchr(SOLR_SPECIAL, sterm[i])) wrbuf_putc(w, '\\'); wrbuf_putc(w, sterm[i]); } else if (sterm[i] == '?' && trunc == 104) { wrbuf_putc(w, '*'); } else if (sterm[i] == '#' && trunc == 104) { wrbuf_putc(w, '?'); } else if (strchr(SOLR_SPECIAL, sterm[i])) { wrbuf_putc(w, '\\'); wrbuf_putc(w, sterm[i]); } else wrbuf_putc(w, sterm[i]); } if (trunc == 1) wrbuf_puts(w, "*"); if (must_quote) wrbuf_puts(w, "\""); } if (ret == 0) pr(wrbuf_cstr(w), client_data); } return ret; }
static int rpn2solr_attr(solr_transform_t ct, Z_AttributeList *attributes, WRBUF w) { const char *relation = solr_lookup_reverse(ct, "relation.", attributes); 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 (!index) index = lookup_index_from_string_attr(attributes); /* Attempt to fix bug #2978: Look for a relation attribute */ if (!relation) relation = lookup_relation_index_from_attr(attributes); if (!index) { solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0); return -1; } /* for serverChoice we omit index+relation+structure */ if (strcmp(index, "solr.serverChoice")) { wrbuf_puts(w, index); if (relation) { if (!strcmp(relation, "exact")) /* TODO Verify if a exact SOLR exists */ relation = ":"; else if (!strcmp(relation, "eq")) relation = ":"; else if (!strcmp(relation, "le")) { /* TODO Not support as such, but could perhaps be transformed into a range relation = ":[ * to "; close_range = "]" */ } else if (!strcmp(relation, "ge")) { /* TODO Not support as such, but could perhaps be transformed into a range relation = "["; relation = ":[ * to "; close_range = "]" */ } /* Missing mapping of not equal, phonetic, stem and relevance */ wrbuf_puts(w, relation); } else wrbuf_puts(w, ":"); if (structure) { if (strcmp(structure, "*")) { wrbuf_puts(w, "/"); wrbuf_puts(w, structure); wrbuf_puts(w, " "); } } } return 0; }