}
-#define REGEX_CHARS "^[]{}()|.*+?!\"$"
+#define REGEX_CHARS "^[]{}()|.*+?!$"
+#define CCL_CHARS "#?\\"
/**
* search_term: Parse CCL search term.
* cclp: CCL Parser
int left_trunc = 0;
int right_trunc = 0;
int regex_trunc = 0;
+ int z3958_trunc = 0;
size_t max = 200;
if (and_list || or_list || !multi)
max = 1;
{
regex_trunc = 1; /* regex trunc (102) allowed */
}
+ else if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_Z3958,
+ &attset))
+ {
+ z3958_trunc = 1; /* Z39.58 trunc (CCL) trunc allowed */
+ }
/* make the RPN token */
p->u.t.term = (char *)xmalloc(len * 2 + 2);
if (regex_trunc && strchr(REGEX_CHARS "\\", src_str[j]))
{
regex_trunc = 2;
- strcat(p->u.t.term, "\\\\");
+ strcat(p->u.t.term, "\\");
}
- if (src_str[j] == '\\')
+ else if (z3958_trunc && strchr(CCL_CHARS "\\", src_str[j]))
+ {
+ z3958_trunc = 2;
strcat(p->u.t.term, "\\");
+ }
strxcat(p->u.t.term, src_str + j, 1);
}
else if (src_str[j] == '"')
strcat(p->u.t.term, ".*");
regex_trunc = 2; /* regex trunc is really needed */
}
+ else if (z3958_trunc)
+ {
+ strcat(p->u.t.term, "?");
+ z3958_trunc = 2;
+ }
else if (i == 0 && j == 0)
left_trunc = 1;
else if (i == no - 1 && j == src_len - 1)
strcat(p->u.t.term, ".");
regex_trunc = 2; /* regex trunc is really needed */
}
+ else if (z3958_trunc)
+ {
+ strcat(p->u.t.term, "#");
+ z3958_trunc = 2;
+ }
else
{
cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
if (regex_trunc && strchr(REGEX_CHARS, src_str[j]))
{
regex_trunc = 2;
- strcat(p->u.t.term, "\\\\");
+ strcat(p->u.t.term, "\\");
+ }
+ else if (z3958_trunc && strchr(CCL_CHARS, src_str[j]))
+ {
+ z3958_trunc = 2;
+ strcat(p->u.t.term, "\\");
}
strxcat(p->u.t.term, src_str + j, 1);
}
{
ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 102);
}
+ else if (z3958_trunc == 2)
+ {
+ ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 104);
+ }
else
{
if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
case 0:
ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r", "term");
- ccl_qual_fitem(bibset, "1=/my/title t=x", "dc.title");
+ ccl_qual_fitem(bibset, "t=x", "reg");
+ ccl_qual_fitem(bibset, "t=z", "z");
+ ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
ccl_qual_fitem(bibset, "r=r", "date");
ccl_qual_fitem(bibset, "r=o", "x");
ccl_qual_fitem(bibset, "dc.title", "title");
strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
ccl_qual_line(bibset, tstline);
- strcpy(tstline, "dc.title 1=/my/title t=x");
+ strcpy(tstline, "reg t=x");
+ ccl_qual_line(bibset, tstline);
+
+ strcpy(tstline, "z t=z");
+ ccl_qual_line(bibset, tstline);
+
+ strcpy(tstline, "dc.title 1=/my/title");
ccl_qual_line(bibset, tstline);
strcpy(tstline, "date r=r # ordered relation");
ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
"term 1=1016 s=al,pw t=r\r\n"
"\n"
- "dc.title 1=/my/title t=x\n"
+ "reg t=x\r\n"
+ "z t=z\r\n"
+ "dc.title 1=/my/title\n"
"date r=r\n"
"x r=o\n"
"title dc.title\n"
" <attr type=\"s\" value=\"al,pw\"/>\n"
" <attr type=\"t\" value=\"r\"/>\n"
" </qual>\n"
+ " <qual name=\"reg\">\n"
+ " <attr type=\"t\" value=\"x\"/>\n"
+ " </qual>\n"
+ " <qual name=\"z\">\n"
+ " <attr type=\"t\" value=\"z\"/>\n"
+ " </qual>\n"
" <qual name=\"dc.title\">\n"
" <attr type=\"1\" value=\"/my/title\"/>\n"
- " <attr type=\"t\" value=\"x\"/>\n"
" </qual>\n"
" <qual name=\"date\">\n"
" <attr type=\"r\" value=\"r\"/>\n"
"@attr 4=2 @attr 1=1016 a "
"@attr 4=2 @attr 1=1016 b "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
- YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=1980",
+ "@attr 2=3 1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990",
+ "@and @attr 2=4 234 @attr 2=2 1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990",
+ "@and @attr 2=4 234 @attr 2=2 1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990",
+ "@and @attr 2=4 234 @attr 2=2 1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990",
+ "@and @attr 2=4 234 @attr 2=2 1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=-1980",
+ "@attr 2=2 1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980",
+ "@attr 2=2 1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "x=-1980",
+ "@attr 2=3 -1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980",
+ "@attr 2=2 1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "x= -1980",
+ "@attr 2=3 -1980 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990",
+ "@attr 2=3 234-1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990",
+ "@and @attr 2=4 234 @attr 2=2 1990 "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b",
+ "@attr 4=1 @attr 1=4 a,b "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b",
+ "@attr 4=1 @attr 1=4 \"a, b\" "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b",
+ "@attr 4=2 @attr 1=4 a-b "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b",
+ "@attr 4=1 @attr 1=4 \"a - b\" "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "a?",
+ "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
YAZ_CHECK(tst_ccl_query(bibset, "a b",
"@and @attr 4=2 @attr 1=1016 a "
"@attr 4=2 @attr 1=1016 b "));
YAZ_CHECK(tst_ccl_query(bibset, "title=a",
"@attr 1=/my/title a "));
- YAZ_CHECK(tst_ccl_query(bibset, "title=a?b#\"c?\"",
- "@attr 5=102 @attr 1=/my/title a.*b.c\\\\? "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=\\(",
- "@attr 5=102 @attr 1=/my/title \\\\( "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=.",
- "@attr 5=102 @attr 1=/my/title \\\\. "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=.",
- "@attr 5=102 @attr 1=/my/title \\\\. "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=\".\"",
- "@attr 5=102 @attr 1=/my/title \\\\. "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=?\\?",
- "@attr 5=102 @attr 1=/my/title .*\\\\? "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=\"?\\?\"",
- "@attr 5=102 @attr 1=/my/title \\\\?\\\\? "));
-
- YAZ_CHECK(tst_ccl_query(bibset, "title=\\\\",
- "@attr 5=102 @attr 1=/my/title \\\\\\\\ "));
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=a?b#\"c?\"",
+ "@attr 5=102 a.*b.c\\\\? "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=a?b#\"c?\"",
+ "@attr 5=104 a?b#c\\\\? "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=\\(",
+ "@attr 5=102 \\\\( "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=\\(",
+ "( "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\"",
+ "\"\\\"\" "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=\\\"",
+ "\"\\\"\" "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=.",
+ "@attr 5=102 \\\\. "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=.",
+ ". "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=\".\"",
+ "@attr 5=102 \\\\. "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=\".\"",
+ ". "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=?\\?",
+ "@attr 5=102 .*\\\\? "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=?\\?",
+ "@attr 5=104 ?\\\\? "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=\"?\\?\"",
+ "@attr 5=102 \\\\?\\\\? "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=\"?\\?\"",
+ "@attr 5=104 \\\\?\\\\? "));
+
+ YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\\",
+ "@attr 5=102 \\\\\\\\ "));
+ YAZ_CHECK(tst_ccl_query(bibset, "z=\\\\",
+ "@attr 5=104 \\\\\\\\ "));
YAZ_CHECK(tst_ccl_query(bibset, "\\\\",
"@attr 4=2 @attr 1=1016 \\\\ "));
{
ret = 1;
}
+ else
+ {
+ yaz_log(YLOG_WARN, " expected: %s", cql ? cql : "null");
+ yaz_log(YLOG_WARN, " got: %s", wrbuf_cstr(w));
+ }
}
}
wrbuf_destroy(w);
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"));
+
+ /* \. is 'eaten' by PQF parser */
+ 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, "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 \"\"", "\"\""));
+ YAZ_CHECK(compare(ct, "@attr 5=1 \"\"", "\"*\""));
+ YAZ_CHECK(compare(ct, "@attr 5=2 \"\"", "\"*\""));
+ YAZ_CHECK(compare(ct, "@attr 5=3 \"\"", "\"**\""));
+ YAZ_CHECK(compare(ct, "@attr 5=102 \"\"", "\"\""));
+ YAZ_CHECK(compare(ct, "@attr 5=104 \"\"", "\"\""));
+
+ YAZ_CHECK(compare(ct, "@attr 5=1 \"water basket\"", "\"water basket*\""));
+ YAZ_CHECK(compare(ct, "@attr 5=2 \"water basket\"", "\"*water basket\""));
+ 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 1=500 abc", 0));