Fix parsing for `max_determinized_states` (#22749)
There was a typo in the `ParseField` declaration. I know we want to port these parsers to `ObjectParser` eventually but I don't have the energy for that today and want to get this fixed. Closes #22722
This commit is contained in:
parent
f1a902865f
commit
ee264c6957
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.apache.lucene.queryparser.classic.MapperQueryParser;
|
||||
import org.apache.lucene.queryparser.classic.QueryParserSettings;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.BoostQuery;
|
||||
import org.apache.lucene.search.FuzzyQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -92,7 +91,7 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
private static final ParseField QUOTE_ANALYZER_FIELD = new ParseField("quote_analyzer");
|
||||
private static final ParseField ALLOW_LEADING_WILDCARD_FIELD = new ParseField("allow_leading_wildcard");
|
||||
private static final ParseField AUTO_GENERATE_PHRASE_QUERIES_FIELD = new ParseField("auto_generate_phrase_queries");
|
||||
private static final ParseField MAX_DETERMINED_STATES_FIELD = new ParseField("max_determined_states");
|
||||
private static final ParseField MAX_DETERMINED_STATES_FIELD = new ParseField("max_determinized_states");
|
||||
private static final ParseField LOWERCASE_EXPANDED_TERMS_FIELD = new ParseField("lowercase_expanded_terms")
|
||||
.withAllDeprecated("Decision is now made by the analyzer");
|
||||
private static final ParseField ENABLE_POSITION_INCREMENTS_FIELD = new ParseField("enable_position_increment");
|
||||
|
@ -796,6 +795,8 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
// ignore, deprecated setting
|
||||
} else if (ALL_FIELDS_FIELD.match(currentFieldName)) {
|
||||
useAllFields = parser.booleanValue();
|
||||
} else if (MAX_DETERMINED_STATES_FIELD.match(currentFieldName)) {
|
||||
maxDeterminizedStates = parser.intValue();
|
||||
} else if (TIME_ZONE_FIELD.match(currentFieldName)) {
|
||||
try {
|
||||
timeZone = parser.text();
|
||||
|
|
|
@ -19,13 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBooleanSubQuery;
|
||||
import static org.hamcrest.CoreMatchers.either;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
import org.apache.lucene.analysis.MockSynonymAnalyzer;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryparser.classic.MapperQueryParser;
|
||||
|
@ -52,7 +45,8 @@ import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
|
|||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.lucene.all.AllTermQuery;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
@ -63,6 +57,13 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBooleanSubQuery;
|
||||
import static org.hamcrest.CoreMatchers.either;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStringQueryBuilder> {
|
||||
|
||||
@Override
|
||||
|
@ -511,6 +512,29 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
assertThat(e.getMessage(), containsString("would result in more than 10000 states"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that {@code max_determinized_states} can be parsed and lowers the allowed number of determinized states.
|
||||
*/
|
||||
public void testToQueryRegExpQueryMaxDeterminizedStatesParsing() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
builder.startObject(); {
|
||||
builder.startObject("query_string"); {
|
||||
builder.field("query", "/[ac]*a[ac]{1,10}/");
|
||||
builder.field("default_field", STRING_FIELD_NAME);
|
||||
builder.field("max_determinized_states", 10);
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
QueryBuilder queryBuilder = new QueryParseContext(createParser(builder)).parseInnerQueryBuilder();
|
||||
TooComplexToDeterminizeException e = expectThrows(TooComplexToDeterminizeException.class,
|
||||
() -> queryBuilder.toQuery(createShardContext()));
|
||||
assertThat(e.getMessage(), containsString("Determinizing [ac]*"));
|
||||
assertThat(e.getMessage(), containsString("would result in more than 10 states"));
|
||||
}
|
||||
|
||||
public void testToQueryFuzzyQueryAutoFuzziness() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
|
@ -784,7 +808,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
" \"tie_breaker\" : 0.0,\n" +
|
||||
" \"default_operator\" : \"or\",\n" +
|
||||
" \"auto_generate_phrase_queries\" : false,\n" +
|
||||
" \"max_determined_states\" : 10000,\n" +
|
||||
" \"max_determinized_states\" : 10000,\n" +
|
||||
" \"enable_position_increment\" : true,\n" +
|
||||
" \"fuzziness\" : \"AUTO\",\n" +
|
||||
" \"fuzzy_prefix_length\" : 0,\n" +
|
||||
|
|
|
@ -29,6 +29,12 @@
|
|||
* The deprecated `minimum_number_should_match` parameter in the `bool` query has
|
||||
been removed, use `minimum_should_match` instead.
|
||||
|
||||
* The `query_string` query now correctly parses the maximum number of
|
||||
states allowed when
|
||||
"https://en.wikipedia.org/wiki/Powerset_construction#Complexity[determinizing]"
|
||||
a regex as `max_determinized_states` instead of the typo
|
||||
`max_determined_states`.
|
||||
|
||||
==== Search shards API
|
||||
|
||||
The search shards API no longer accepts the `type` url parameter, which didn't
|
||||
|
|
Loading…
Reference in New Issue