Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (revision 802758) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (working copy) @@ -222,6 +222,12 @@ 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 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 @@ // 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 @@ 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() { Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java (revision 802757) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java (working copy) @@ -230,6 +230,12 @@ 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 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 @@ // 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 { Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java (revision 802757) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java (working copy) @@ -33,12 +33,8 @@ private static final long serialVersionUID = -2804763012723049527L; - private boolean allowLeadingWildcard = true; + private boolean allowLeadingWildcard = false; // default in 2.9 - public AllowLeadingWildcardAttributeImpl() { - allowLeadingWildcard = true; // default in 2.4 - } - public void setAllowLeadingWildcard(boolean allowLeadingWildcard) { this.allowLeadingWildcard = allowLeadingWildcard; }