static int check_range(solr_transform_t ct, Z_Complex *q, Z_AttributesPlusTerm **p_apt1, Z_AttributesPlusTerm **p_apt2) { Z_Operator *op = q->roperator; if (op->which == Z_Operator_and && q->s1->which == Z_RPNStructure_simple && q->s2->which == Z_RPNStructure_simple && q->s1->u.simple->which == Z_Operand_APT && q->s2->u.simple->which == Z_Operand_APT) { Z_AttributesPlusTerm *apt1 = q->s1->u.simple->u.attributesPlusTerm; Z_AttributesPlusTerm *apt2 = q->s2->u.simple->u.attributesPlusTerm; const char *i1 = solr_lookup_reverse(ct, "index.", apt1->attributes); const char *i2 = solr_lookup_reverse(ct, "index.", apt2->attributes); const char *rel1 = solr_lookup_reverse(ct, "relation.", apt1->attributes); const char *rel2 = solr_lookup_reverse(ct, "relation.", apt2->attributes); if (!rel1) rel1 = lookup_relation_index_from_attr(apt1->attributes); if (!rel2) rel2 = lookup_relation_index_from_attr(apt2->attributes); if (!i1) i1 = lookup_index_from_string_attr(apt1->attributes); if (!i2) i2 = lookup_index_from_string_attr(apt2->attributes); if (i1 && i2 && !strcmp(i1, i2) && rel1 && rel2) { if ((rel1[0] == '>' || rel1[0] == 'g') && (rel2[0] == '<' || rel2[0] == 'l')) { *p_apt1 = apt1; *p_apt2 = apt2; return 1; } if ((rel2[0] == '>' || rel2[0] == 'g') && (rel1[0] == '<' || rel1[0] == 'l')) { *p_apt1 = apt2; *p_apt2 = apt1; return 1; } } } return 0; }
static int rpn2cql_attr(cql_transform_t ct, Z_AttributeList *attributes, WRBUF w) { const char *relation = cql_lookup_reverse(ct, "relation.", attributes); const char *index = cql_lookup_reverse(ct, "index.", attributes); const char *structure = cql_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) { cql_transform_set_error(ct, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0); return -1; } /* for serverChoice we omit index+relation+structure */ if (strcmp(index, "cql.serverChoice")) { wrbuf_puts(w, index); if (relation) { if (!strcmp(relation, "exact")) relation = "=="; else if (!strcmp(relation, "eq")) relation = "="; else if (!strcmp(relation, "le")) relation = "<="; else if (!strcmp(relation, "ge")) relation = ">="; /* 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; }
static int rpn2solr_simple(solr_transform_t ct, void (*pr)(const char *buf, void *client_data), void *client_data, Z_AttributesPlusTerm *apt, WRBUF w, Z_AttributesPlusTerm *apt2) { int ret = 0; Z_Term *term = apt->term; Odr_int trunc = get_truncation(apt); const char *relation2 = 0; const char *relation1 = solr_lookup_reverse(ct, "relation.", apt->attributes); /* Attempt to fix bug #2978: Look for a relation attribute */ if (!relation1) relation1 = lookup_relation_index_from_attr(apt->attributes); if (!relation1) { return YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; } if (apt2) { relation2 = solr_lookup_reverse(ct, "relation.", apt2->attributes); if (!relation2) relation2 = lookup_relation_index_from_attr(apt2->attributes); } wrbuf_rewind(w); ret = rpn2solr_attr(ct, apt->attributes, w); if (ret) return ret; if ((trunc >= 0 && trunc <= 3) || trunc == 100 || trunc == 104) ; else { return YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE; } if (!relation1) ret = emit_term(ct, w, term, trunc); else if (relation1[0] == '<' || relation1[0] == 'l') { wrbuf_puts(w, "[* TO "); ret = emit_term(ct, w, term, trunc); if (!strcmp(relation1, "le") || !strcmp(relation1, "<=")) wrbuf_puts(w, "]"); else wrbuf_puts(w, "}"); } else if (relation1[0] == '>' || relation1[0] == 'g') { if (!strcmp(relation1, ">=") || !strcmp(relation1, "ge")) wrbuf_puts(w, "["); else wrbuf_puts(w, "{"); ret = emit_term(ct, w, term, trunc); wrbuf_puts(w, " TO "); if (apt2) { emit_term(ct, w, apt2->term, 0); if (!relation2 || !strcmp(relation2, "<=") || !strcmp(relation2, "le")) wrbuf_puts(w, "]"); else wrbuf_puts(w, "}"); } else wrbuf_puts(w, "*]"); } else ret = emit_term(ct, w, term, trunc); 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; }