Apache Lucene open-source search software
LUCENE-1795: disable leading wildcard by default in new QueryParser, matching 2.4
Michael McCandless08c69caca632
diff --git a/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java b/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.javaindex 076639777fd..85bd521bac2 100644--- a/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java+++ b/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java@@ -33,11 +33,7 @@ public class AllowLeadingWildcardAttributeImpl extends AttributeImplprivate static final long serialVersionUID = -2804763012723049527L;- private boolean allowLeadingWildcard = true;-- public AllowLeadingWildcardAttributeImpl() {- allowLeadingWildcard = true; // default in 2.4- }+ private boolean allowLeadingWildcard = false; // default in 2.9public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {this.allowLeadingWildcard = allowLeadingWildcard;diff --git a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.javaindex 58118de3556..f75029ff98c 100644--- a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java+++ b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java@@ -222,6 +222,12 @@ public class TestQPHelper extends LuceneTestCase {return getParser(a).parse(query, "field");}+ public Query getQueryAllowLeadingWildcard(String query, Analyzer a) throws Exception {+ StandardQueryParser parser = getParser(a);+ parser.setAllowLeadingWildcard(true);+ return parser.parse(query, "field");+ }+public void assertQueryEquals(String query, Analyzer a, String result)throws Exception {Query q = getQuery(query, a);@@ -232,6 +238,16 @@ public class TestQPHelper extends LuceneTestCase {}}+ public void assertQueryEqualsAllowLeadingWildcard(String query, Analyzer a, String result)+ throws Exception {+ Query q = getQueryAllowLeadingWildcard(query, a);+ String s = q.toString("field");+ if (!s.equals(result)) {+ fail("Query /" + query + "/ yielded /" + s + "/, expecting /" + result+ + "/");+ }+ }+public void assertQueryEquals(StandardQueryParser qp, String field,String query, String result) throws Exception {Query q = qp.parse(query, field);@@ -306,7 +322,7 @@ public class TestQPHelper extends LuceneTestCase {// used google to translate the word "term" to japanese -> ??assertQueryEquals("term\u3000term\u3000term", null,"term\u0020term\u0020term");- assertQueryEquals("??\u3000??\u3000??", null, "??\u0020??\u0020??");+ assertQueryEqualsAllowLeadingWildcard("??\u3000??\u3000??", null, "??\u0020??\u0020??");}public void testSimple() throws Exception {@@ -910,6 +926,7 @@ public class TestQPHelper extends LuceneTestCase {assertQueryNodeException("field:term:with:colon some more terms");assertQueryNodeException("(sub query)^5.0^2.0 plus more");assertQueryNodeException("secret AND illegal) AND access:confidential");+ assertQueryNodeException("*leadingWildcard"); // disallowed by default}public void testCustomQueryParserWildcard() {diff --git a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.javaindex 6eddc00c35f..d172059603c 100644--- a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java+++ b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java@@ -230,6 +230,12 @@ public class TestQueryParserWrapper extends LuceneTestCase {return getParser(a).parse(query);}+ public Query getQueryAllowLeadingWildcard(String query, Analyzer a) throws Exception {+ QueryParserWrapper parser = getParser(a);+ parser.setAllowLeadingWildcard(true);+ return parser.parse(query);+ }+public void assertQueryEquals(String query, Analyzer a, String result)throws Exception {Query q = getQuery(query, a);@@ -240,6 +246,15 @@ public class TestQueryParserWrapper extends LuceneTestCase {}}+ public void assertQueryEqualsAllowLeadingWildcard(String query, Analyzer a, String result)+ throws Exception {+ Query q = getQueryAllowLeadingWildcard(query, a);+ String s = q.toString("field");+ if (!s.equals(result)) {+ fail("Query /" + query + "/ yielded /" + s + "/, expecting /" + result+ + "/");+ }+ }public void assertQueryEquals(QueryParserWrapper qp, String field,String query, String result) throws Exception {Query q = qp.parse(query);@@ -311,7 +326,7 @@ public class TestQueryParserWrapper extends LuceneTestCase {// used google to translate the word "term" to japanese -> ??assertQueryEquals("term\u3000term\u3000term", null,"term\u0020term\u0020term");- assertQueryEquals("??\u3000??\u3000??", null, "??\u0020??\u0020??");+ assertQueryEqualsAllowLeadingWildcard("??\u3000??\u3000??", null, "??\u0020??\u0020??");}public void testSimple() throws Exception {