From 24357780de7d01b3c3ec2c3f6715b2feee7d0e76 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 1 Nov 2011 14:03:14 +0100 Subject: [PATCH] Report 'too many characters in search..' Make proper diagnostic for too many characters in search term. And make a test case for it. --- index/zaptterm.c | 6 +++++- test/api/test_search.c | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/index/zaptterm.c b/index/zaptterm.c index 7c83e2f..425dfa3 100644 --- a/index/zaptterm.c +++ b/index/zaptterm.c @@ -50,9 +50,13 @@ ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt, &outbuf, &outleft); if (ret == (size_t)(-1)) { + int iconv_error = yaz_iconv_error(zh->iconv_to_utf8); + ret = yaz_iconv(zh->iconv_to_utf8, 0, 0, 0, 0); zebra_setError( - zh, + zh, + iconv_error == YAZ_ICONV_E2BIG ? + YAZ_BIB1_TOO_MANY_CHARS_IN_SEARCH_STATEMENT : YAZ_BIB1_QUERY_TERM_INCLUDES_CHARS_THAT_DO_NOT_TRANSLATE_INTO_, 0); return ZEBRA_FAIL; diff --git a/test/api/test_search.c b/test/api/test_search.c index 423f76c..51b405e 100644 --- a/test/api/test_search.c +++ b/test/api/test_search.c @@ -59,6 +59,17 @@ const char *myrec[] = { " 2107-09-19 00:00:00\n" "\n" , + "\n" + "" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "12345" + "" + "" + , 0} ; static void tst(int argc, char **argv) @@ -157,14 +168,36 @@ static void tst(int argc, char **argv) /* string relations, < */ YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 0", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 my", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 my", 1)); /* string relations, <= */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 my", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 mn", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 my", 4)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 mn", 1)); /* = */ YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=3 my", 3)); + YAZ_CHECK( + tl_query(zh, + "@attr 1=4 @attr 2=3 " + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "12345" + , 1)); + + YAZ_CHECK( + tl_query_x(zh, + "@attr 1=4 @attr 2=3 " + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "1234567890" "1234567890""1234567890""1234567890""1234567890" + "123456" + , 0, 11)); + /* string relations, >= */ YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 x", 2)); @@ -177,8 +210,8 @@ static void tst(int argc, char **argv) YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 title", 2)); /* always-matches relation */ - YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {ym}", 5)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 {x my}", 4)); + YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {ym}", 6)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 {x my}", 5)); YAZ_CHECK(tl_query_x(zh, "@attr 1=1 @attr 2=103 {x my}", 0, 114)); /* and searches */ -- 1.7.10.4