From: Dennis Schafroth Date: Wed, 4 Nov 2009 14:33:58 +0000 (+0100) Subject: Addded a lookup of relation in the attributes. Not supporting the phonetic, stem... X-Git-Tag: v3.0.51~21 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=9f16968f01f8ffc7421be4bda437c69ee7e11eba Addded a lookup of relation in the attributes. Not supporting the phonetic, stem and relevance as these are not listed on the CQL web page. --- diff --git a/src/rpn2cql.c b/src/rpn2cql.c index 81ca550..1fa9aa3 100644 --- a/src/rpn2cql.c +++ b/src/rpn2cql.c @@ -46,6 +46,67 @@ static const char *lookup_index_from_string_attr(Z_AttributeList *attributes) return 0; } +static const char *lookup_relation_index_from_attr(Z_AttributeList *attributes) +{ + int j; + int server_choice = 1; + for (j = 0; j < attributes->num_attributes; j++) + { + Z_AttributeElement *ae = attributes->attributes[j]; + if (*ae->attributeType == 2) /* relation attribute */ + { + if (ae->which == Z_AttributeValue_numeric) + { + /* Only support for numeric relation */ + Odr_int *relation = ae->value.numeric; + /* map this numeric to represetation in cql */ + switch (*relation) { + /* Unsure on whether this is the relation attribute + const? */ + case Z_ProximityOperator_Prox_lessThan: + return "<"; + case Z_ProximityOperator_Prox_lessThanOrEqual: + return "<="; + case Z_ProximityOperator_Prox_equal: + return "="; + case Z_ProximityOperator_Prox_greaterThanOrEqual: + return ">="; + case Z_ProximityOperator_Prox_greaterThan: + return ">"; + case Z_ProximityOperator_Prox_notEqual: + return "<>"; + + /* phonetic */ + case 100: + return "??"; + + /* stem */ + case 101: + return "??"; + + /* relevance */ + case 102: + return "??"; + otherwise: + /* Invalid relation */ + return 0; + } + + } + else { + /* Can we have a complex relation value? + Should we implement something? + */ + } + + server_choice = 0; /* Which ServerChoice if relation? */ + } + } + if (server_choice) + return "cql.serverChoice"; + return 0; +} + static int rpn2cql_attr(cql_transform_t ct, Z_AttributeList *attributes, WRBUF w) { @@ -58,6 +119,10 @@ static int rpn2cql_attr(cql_transform_t ct, 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, @@ -78,6 +143,7 @@ static int rpn2cql_attr(cql_transform_t ct, relation = "<="; else if (!strcmp(relation, "ge")) relation = ">="; + /* Missing mapping of not equal, phonetic, stem and relevance */ wrbuf_puts(w, relation); } else