From e88537522d6516efbc584494f16986aac4060318 Mon Sep 17 00:00:00 2001 From: reger Date: Sat, 16 Aug 2014 14:29:52 +0200 Subject: [PATCH] allow single quote " ' " in query see http://mantis.tokeek.de/view.php?id=379 -add QueryGoal test case for this --- source/net/yacy/search/query/QueryGoal.java | 2 +- test/net/yacy/search/query/QueryGoalTest.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/net/yacy/search/query/QueryGoalTest.java diff --git a/source/net/yacy/search/query/QueryGoal.java b/source/net/yacy/search/query/QueryGoal.java index 455955da2..a9d0b06ab 100644 --- a/source/net/yacy/search/query/QueryGoal.java +++ b/source/net/yacy/search/query/QueryGoal.java @@ -52,7 +52,7 @@ public class QueryGoal { private static char space = ' '; private static char sq = '\''; private static char dq = '"'; - private static String seps = ".:;#'*`,!$%()=?^<>/&_"; + private static String seps = ".:;#*`,!$%()=?^<>/&_"; public String query_original; private HandleSet include_hashes, exclude_hashes; diff --git a/test/net/yacy/search/query/QueryGoalTest.java b/test/net/yacy/search/query/QueryGoalTest.java new file mode 100644 index 000000000..74387082c --- /dev/null +++ b/test/net/yacy/search/query/QueryGoalTest.java @@ -0,0 +1,38 @@ +package net.yacy.search.query; + +import java.util.HashMap; +import java.util.Iterator; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class QueryGoalTest { + + /** + * Test of getIncludeString method, of class QueryGoal. + */ + @Test + public void testGetIncludeString() { + HashMap testdata = new HashMap(); + // Prameter: (Query, [result_term1, result_term2 ..]) + testdata.put("O'Reily's book", new String[]{"o'reily's", "book"}); + testdata.put("\"O'Reily's book\"", new String[]{"o'reily's book"}); // quoted term + testdata.put("\"O'Reily's\" +book", new String[]{"o'reily's", "book"}); // +word + testdata.put("Umphrey's + McGee", new String[]{"umphrey's", "mcgee"}); + testdata.put("'The Book' library", new String[]{"the book","library"}); //single quoted term + + for (String testquery : testdata.keySet()) { + QueryGoal qg = new QueryGoal(testquery); // get test query + String[] singlestr = testdata.get(testquery); // get result strings + + Iterator it = qg.getIncludeStrings(); + int i = 0; + while (it.hasNext()) { + String s = it.next(); + System.out.println(singlestr[i] + " = " + s); + assertEquals(s, singlestr[i]); + i++; + } + } + } + +}