+#include <yaz/logrpn.h> /* For yaz_prox_unit_name() */
+
+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;
+ int server_choice = 1;
+ for (j = 0; j < attributes->num_attributes; j++)
+ {
+ Z_AttributeElement *ae = attributes->attributes[j];
+ if (*ae->attributeType == 1) /* use attribute */
+ {
+ if (ae->which == Z_AttributeValue_complex)
+ {
+ Z_ComplexAttribute *ca = ae->value.complex;
+ int i;
+ for (i = 0; i < ca->num_list; i++)
+ {
+ Z_StringOrNumeric *son = ca->list[i];
+ if (son->which == Z_StringOrNumeric_string)
+ return son->u.string;
+ }
+ }
+ server_choice = 0; /* not serverChoice because we have use attr */
+ }
+ }
+ if (server_choice)
+ return "cql.serverChoice";
+ return 0;
+}
+
+static const char *lookup_relation_index_from_attr(Z_AttributeList *attributes)
+{
+ int j;
+ 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 representation in CQL */
+ switch (*relation)
+ {
+ /* Unsure on whether this is the relation attribute constants? */
+ 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 "<>";
+ case 100:
+ /* phonetic is not supported in CQL */
+ return 0;
+ case 101:
+ /* stem is not supported in CQL */
+ return 0;
+ case 102:
+ /* relevance is supported in CQL, but not implemented yet */
+ return 0;
+ default:
+ /* Invalid relation */
+ return 0;
+ }
+ }
+ else {
+ /* Can we have a complex relation value?
+ Should we implement something?
+ */
+ }
+ }
+ }
+ return "=";
+}