Minor fixes to the `match` query.

Fixed documentation since the default rewrite method for fuzzy queries is to
select top terms, fixed usage of the fuzzy rewrite method, and removed unused
`rewrite` parameter.

Close #6932
This commit is contained in:
Adrien Grand 2015-07-08 16:20:58 +02:00
parent 8661ab0bf9
commit da5fa6c4f3
4 changed files with 3 additions and 13 deletions

View File

@ -123,8 +123,6 @@ public class MatchQueryParser implements QueryParser {
} }
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
minimumShouldMatch = parser.textOrNull(); minimumShouldMatch = parser.textOrNull();
} else if ("rewrite".equals(currentFieldName)) {
matchQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null));
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) { } else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null)); matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null));
} else if ("fuzzy_transpositions".equals(currentFieldName)) { } else if ("fuzzy_transpositions".equals(currentFieldName)) {

View File

@ -113,8 +113,6 @@ public class MultiMatchQueryParser implements QueryParser {
} }
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
minimumShouldMatch = parser.textOrNull(); minimumShouldMatch = parser.textOrNull();
} else if ("rewrite".equals(currentFieldName)) {
multiMatchQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null));
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) { } else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
multiMatchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null)); multiMatchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(parseContext.parseFieldMatcher(), parser.textOrNull(), null));
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) { } else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.support.QueryParsers; import org.elasticsearch.index.query.support.QueryParsers;
@ -68,8 +67,6 @@ public class MatchQuery {
protected boolean transpositions = FuzzyQuery.defaultTranspositions; protected boolean transpositions = FuzzyQuery.defaultTranspositions;
protected MultiTermQuery.RewriteMethod rewriteMethod;
protected MultiTermQuery.RewriteMethod fuzzyRewriteMethod; protected MultiTermQuery.RewriteMethod fuzzyRewriteMethod;
protected boolean lenient; protected boolean lenient;
@ -118,10 +115,6 @@ public class MatchQuery {
this.transpositions = transpositions; this.transpositions = transpositions;
} }
public void setRewriteMethod(MultiTermQuery.RewriteMethod rewriteMethod) {
this.rewriteMethod = rewriteMethod;
}
public void setFuzzyRewriteMethod(MultiTermQuery.RewriteMethod fuzzyRewriteMethod) { public void setFuzzyRewriteMethod(MultiTermQuery.RewriteMethod fuzzyRewriteMethod) {
this.fuzzyRewriteMethod = fuzzyRewriteMethod; this.fuzzyRewriteMethod = fuzzyRewriteMethod;
} }
@ -278,10 +271,11 @@ public class MatchQuery {
if (query instanceof FuzzyQuery) { if (query instanceof FuzzyQuery) {
QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod); QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
} }
return query;
} }
int edits = fuzziness.asDistance(term.text()); int edits = fuzziness.asDistance(term.text());
FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions); FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions);
QueryParsers.setRewriteMethod(query, rewriteMethod); QueryParsers.setRewriteMethod(query, fuzzyRewriteMethod);
return query; return query;
} }
if (fieldType != null) { if (fieldType != null) {

View File

@ -46,7 +46,7 @@ See <<fuzziness>> for allowed settings.
The `prefix_length` and The `prefix_length` and
`max_expansions` can be set in this case to control the fuzzy process. `max_expansions` can be set in this case to control the fuzzy process.
If the fuzzy option is set the query will use `constant_score_rewrite` If the fuzzy option is set the query will use `top_terms_blended_freqs_${max_expansions}`
as its <<query-dsl-multi-term-rewrite,rewrite as its <<query-dsl-multi-term-rewrite,rewrite
method>> the `fuzzy_rewrite` parameter allows to control how the query will get method>> the `fuzzy_rewrite` parameter allows to control how the query will get
rewritten. rewritten.