From 5b4588515be16de8c34adafc9b94c971d4b93ffe Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 14 Jul 2015 19:43:34 +0000 Subject: [PATCH] LUCENE-6677: QueryParser should pass its maxDeterminizedStates when creating WildcardQuery git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1691066 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 +++ .../queryparser/classic/QueryParserBase.java | 2 +- .../queryparser/classic/TestQueryParser.java | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 0412f1fa77d..b8a71911986 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -253,6 +253,9 @@ Bug fixes * LUCENE-6658: Fix IndexUpgrader to also upgrade indexes without any segments. (Trejkaz, Uwe Schindler) +* LUCENE-6677: QueryParserBase fails to enforce maxDeterminizedStates when + creating a WildcardQuery (David Causse via Mike McCandless) + Changes in Runtime Behavior * LUCENE-6501: The subreader structure in ParallelCompositeReader diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java index be79878d416..49627291969 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java @@ -670,7 +670,7 @@ public abstract class QueryParserBase extends QueryBuilder implements CommonQuer * @return new WildcardQuery instance */ protected Query newWildcardQuery(Term t) { - WildcardQuery query = new WildcardQuery(t); + WildcardQuery query = new WildcardQuery(t, maxDeterminizedStates); query.setRewriteMethod(multiTermRewriteMethod); return query; } diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java index 7c4f2a6fce4..9d24e538a4e 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java @@ -17,8 +17,6 @@ package org.apache.lucene.queryparser.classic; * limitations under the License. */ -import java.io.IOException; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -37,6 +35,9 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.MultiPhraseQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.util.automaton.TooComplexToDeterminizeException; + +import java.io.IOException; /** * Tests QueryParser. @@ -504,5 +505,16 @@ public class TestQueryParser extends QueryParserTestBase { expected.setSlop(3); assertEquals(expected, qp.parse("\"中国\"~3^2")); } - + + /** LUCENE-6677: make sure wildcard query respects maxDeterminizedStates. */ + public void testWildcardMaxDeterminizedStates() throws Exception { + QueryParser qp = new QueryParser("field", new MockAnalyzer(random())); + qp.setMaxDeterminizedStates(10); + try { + qp.parse("a*aaaaaaa"); + fail("should have hit exception"); + } catch (TooComplexToDeterminizeException tctde) { + // expected + } + } }