rpn2cql diagnostics: provide use attribute addinfo YAZ-853
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Aug 2015 11:23:29 +0000 (13:23 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Aug 2015 11:23:29 +0000 (13:23 +0200)
src/rpn2cql.c
test/test_rpn2cql.c

index b0a6e43..b09d6a4 100644 (file)
@@ -20,7 +20,8 @@
 #include <yaz/wrbuf.h>
 #include <yaz/logrpn.h> /* For yaz_prox_unit_name() */
 
 #include <yaz/wrbuf.h>
 #include <yaz/logrpn.h> /* For yaz_prox_unit_name() */
 
-static const char *lookup_index_from_string_attr(Z_AttributeList *attributes)
+static const char *lookup_index_from_string_attr(Z_AttributeList *attributes,
+                                                 Odr_int *numeric_value)
 {
     int j;
     int server_choice = 1;
 {
     int j;
     int server_choice = 1;
@@ -40,6 +41,10 @@ static const char *lookup_index_from_string_attr(Z_AttributeList *attributes)
                         return son->u.string;
                 }
             }
                         return son->u.string;
                 }
             }
+            else if (ae->which == Z_AttributeValue_numeric)
+            {
+                *numeric_value = *ae->value.numeric;
+            }
             server_choice = 0; /* not serverChoice because we have use attr */
         }
     }
             server_choice = 0; /* not serverChoice because we have use attr */
         }
     }
@@ -107,19 +112,23 @@ static int rpn2cql_attr(cql_transform_t ct,
     const char *index = cql_lookup_reverse(ct, "index.", attributes);
     const char *structure = cql_lookup_reverse(ct, "structure.", 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 transform (properties) do not match, we'll fall back
+       to string or report numeric attribute error */
     if (!index)
     if (!index)
-        index = lookup_index_from_string_attr(attributes);
-
-    /* Attempt to fix bug #2978: Look for a relation attribute */
+    {
+        Odr_int use_attribute = -1;
+        index = lookup_index_from_string_attr(attributes, &use_attribute);
+        if (!index)
+        {
+            wrbuf_rewind(w);
+            if (use_attribute != -1)
+                wrbuf_printf(w, ODR_INT_PRINTF, use_attribute);
+            return YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
+        }
+    }
     if (!relation)
         relation = lookup_relation_index_from_attr(attributes);
 
     if (!relation)
         relation = lookup_relation_index_from_attr(attributes);
 
-    if (!index)
-    {
-        wrbuf_rewind(w);
-        return YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
-    }
     if (!relation)
         relation = "=";
     else if (!strcmp(relation, "exact"))
     if (!relation)
         relation = "=";
     else if (!strcmp(relation, "exact"))
index 0d05fab..2dba3cf 100644 (file)
@@ -82,7 +82,7 @@ static void tst1(void)
     YAZ_CHECK(compare(ct, "@and @and a b @and c d", "(a and b) and (c and d)"));
 
     YAZ_CHECK(compare(ct, "@attr 1=field abc", "field=abc"));
     YAZ_CHECK(compare(ct, "@and @and a b @and c d", "(a and b) and (c and d)"));
 
     YAZ_CHECK(compare(ct, "@attr 1=field abc", "field=abc"));
-    YAZ_CHECK(compare2(ct, "@attr 1=4 abc", 0, 114)); /* should fail */
+    YAZ_CHECK(compare2(ct, "@attr 1=4 abc", "4", 114)); /* should fail */
 
     cql_transform_define_pattern(ct, "index.title", "1=4");
     YAZ_CHECK(compare(ct, "@attr 1=4 abc", "title=abc"));
 
     cql_transform_define_pattern(ct, "index.title", "1=4");
     YAZ_CHECK(compare(ct, "@attr 1=4 abc", "title=abc"));
@@ -168,7 +168,7 @@ static void tst2(void)
 
     /* Other */
     YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1"));
 
     /* Other */
     YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1"));
-    YAZ_CHECK(compare2(ct, "@attr 1=500 abc", 0, 114));
+    YAZ_CHECK(compare2(ct, "@attr 1=500 abc", "500", 114));
     YAZ_CHECK(compare2(ct, "@attr 5=99 x", "99", 120));
     cql_transform_close(ct);
     wrbuf_destroy(w);
     YAZ_CHECK(compare2(ct, "@attr 5=99 x", "99", 120));
     cql_transform_close(ct);
     wrbuf_destroy(w);