mirror of
https://github.com/apache/lucene.git
synced 2025-02-22 01:56:16 +00:00
LUCENE-1795: disable leading wildcard by default in new QueryParser, matching 2.4
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@802794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35ea5c1350
commit
08c69caca6
@ -33,11 +33,7 @@ public class AllowLeadingWildcardAttributeImpl extends AttributeImpl
|
||||
|
||||
private static final long serialVersionUID = -2804763012723049527L;
|
||||
|
||||
private boolean allowLeadingWildcard = true;
|
||||
|
||||
public AllowLeadingWildcardAttributeImpl() {
|
||||
allowLeadingWildcard = true; // default in 2.4
|
||||
}
|
||||
private boolean allowLeadingWildcard = false; // default in 2.9
|
||||
|
||||
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
|
||||
this.allowLeadingWildcard = allowLeadingWildcard;
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user