From 85a0aae5ecc05652b0cf16aae811d64846835f80 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 Dec 2011 14:49:34 +0100 Subject: [PATCH] RPN to CQL: always quote resulting terms For bizarre reasons, JSTOR's SRU server returns 0 hits on ISSN searches unless a CQL term is quoted. The rpn2cql family of functions now always returns quoted CQL terms. --- src/rpn2cql.c | 9 ++---- test/test_rpn2cql.c | 84 +++++++++++++++++++++++++-------------------------- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/rpn2cql.c b/src/rpn2cql.c index 9fedba6..43f09ec 100644 --- a/src/rpn2cql.c +++ b/src/rpn2cql.c @@ -194,7 +194,6 @@ static int rpn2cql_simple(cql_transform_t ct, size_t lterm = 0; Odr_int trunc = lookup_truncation(apt->attributes); size_t i; - int must_quote = 0; wrbuf_rewind(w); ret = rpn2cql_attr(ct, apt->attributes, w); @@ -222,10 +221,7 @@ static int rpn2cql_simple(cql_transform_t ct, for (i = 0 ; i < lterm; i++) if (strchr(" ()=>1980")); - YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=2 1980", "dc.date<=1980")); - YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=4 1980", "dc.date>=1980")); + YAZ_CHECK(compare(ct, "@attr 2=1 @attr 1=30 1980", "dc.date<\"1980\"")); + YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=3 1980", "dc.date=\"1980\"")); + YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=5 1980", "dc.date>\"1980\"")); + YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=2 1980", "dc.date<=\"1980\"")); + YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=4 1980", "dc.date>=\"1980\"")); /* Truncation */ - YAZ_CHECK(compare(ct, "@attr 5=1 water", "water*")); - YAZ_CHECK(compare(ct, "@attr 5=2 water", "*water")); - YAZ_CHECK(compare(ct, "@attr 5=3 water", "*water*")); - YAZ_CHECK(compare(ct, "@attr 5=100 water", "water")); - YAZ_CHECK(compare(ct, "@attr 5=102 water", "water")); - YAZ_CHECK(compare(ct, "@attr 5=104 water", "water")); - - YAZ_CHECK(compare(ct, "@attr 5=102 wat.*er", "wat*er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat?er", "wat*er")); - - YAZ_CHECK(compare(ct, "@attr 5=102 wat.er", "wat?er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat#er", "wat?er")); - YAZ_CHECK(compare(ct, "@attr 5=102 wat?er", "wat\\?er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat*er", "wat\\*er")); - YAZ_CHECK(compare(ct, "@attr 5=102 wat#er", "wat#er")); + YAZ_CHECK(compare(ct, "@attr 5=1 water", "\"water*\"")); + YAZ_CHECK(compare(ct, "@attr 5=2 water", "\"*water\"")); + YAZ_CHECK(compare(ct, "@attr 5=3 water", "\"*water*\"")); + YAZ_CHECK(compare(ct, "@attr 5=100 water", "\"water\"")); + YAZ_CHECK(compare(ct, "@attr 5=102 water", "\"water\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 water", "\"water\"")); + + YAZ_CHECK(compare(ct, "@attr 5=102 wat.*er", "\"wat*er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat?er", "\"wat*er\"")); + + YAZ_CHECK(compare(ct, "@attr 5=102 wat.er", "\"wat?er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat#er", "\"wat?er\"")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat?er", "\"wat\\?er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat*er", "\"wat\\*er\"")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat#er", "\"wat#er\"")); /* \. is 'eaten' by PQF parser */ - YAZ_CHECK(compare(ct, "@attr 5=102 wat\\.er", "wat?er")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat\\.er", "\"wat?er\"")); /* Escape sequences */ /* note: escape sequences that survive after PQF parse below */ - YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\?er", "wat\\?er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\?er", "wat\\?er")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\?er", "\"wat\\?er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\?er", "\"wat\\?er\"")); - YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\*er", "wat\\*er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\*er", "wat\\*er")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\*er", "\"wat\\*er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\*er", "\"wat\\*er\"")); - YAZ_CHECK(compare(ct, "wat\\\\#er", "wat#er")); - YAZ_CHECK(compare(ct, "@attr 5=100 wat\\\\#er", "wat#er")); - YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\#er", "wat#er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\#er", "wat#er")); - YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\.er", "wat.er")); - YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\.er", "wat.er")); + YAZ_CHECK(compare(ct, "wat\\\\#er", "\"wat#er\"")); + YAZ_CHECK(compare(ct, "@attr 5=100 wat\\\\#er", "\"wat#er\"")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\#er", "\"wat#er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\#er", "\"wat#er\"")); + YAZ_CHECK(compare(ct, "@attr 5=102 wat\\\\.er", "\"wat.er\"")); + YAZ_CHECK(compare(ct, "@attr 5=104 wat\\\\.er", "\"wat.er\"")); /* Quoting */ YAZ_CHECK(compare(ct, "@attr 5=100 \"\"", "\"\"")); @@ -144,7 +144,7 @@ static void tst2(void) YAZ_CHECK(compare(ct, "@attr 5=3 \"water basket\"", "\"*water basket*\"")); /* Other */ - YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1")); + YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=\"1\"")); YAZ_CHECK(compare(ct, "@attr 1=500 abc", 0)); cql_transform_close(ct); wrbuf_destroy(w); -- 1.7.10.4