Query DSL: `query_string` - Expose QueryParser#setAutoGeneratePhraseQueries, closes #964.

This commit is contained in:
kimchy 2011-05-25 03:58:59 +03:00
parent e022f744ee
commit b76f5150ee
4 changed files with 16 additions and 0 deletions

View File

@ -86,6 +86,7 @@ public class MapperQueryParser extends QueryParser {
this.analyzer = settings.analyzer();
setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
setEnablePositionIncrements(settings.enablePositionIncrements());
setAutoGeneratePhraseQueries(settings.autoGeneratePhraseQueries());
setAllowLeadingWildcard(settings.allowLeadingWildcard());
setLowercaseExpandedTerms(settings.lowercaseExpandedTerms());
setPhraseSlop(settings.phraseSlop());

View File

@ -31,6 +31,7 @@ public class QueryParserSettings {
private String defaultField;
private float boost = 1.0f;
private MapperQueryParser.Operator defaultOperator = QueryParser.Operator.OR;
private boolean autoGeneratePhraseQueries = false;
private boolean allowLeadingWildcard = true;
private boolean lowercaseExpandedTerms = true;
private boolean enablePositionIncrements = true;
@ -73,6 +74,14 @@ public class QueryParserSettings {
this.defaultOperator = defaultOperator;
}
public boolean autoGeneratePhraseQueries() {
return autoGeneratePhraseQueries;
}
public void autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) {
this.autoGeneratePhraseQueries = autoGeneratePhraseQueries;
}
public boolean allowLeadingWildcard() {
return allowLeadingWildcard;
}
@ -151,6 +160,7 @@ public class QueryParserSettings {
QueryParserSettings that = (QueryParserSettings) o;
if (autoGeneratePhraseQueries != that.autoGeneratePhraseQueries()) return false;
if (allowLeadingWildcard != that.allowLeadingWildcard) return false;
if (Float.compare(that.boost, boost) != 0) return false;
if (enablePositionIncrements != that.enablePositionIncrements) return false;
@ -173,6 +183,7 @@ public class QueryParserSettings {
result = 31 * result + (defaultField != null ? defaultField.hashCode() : 0);
result = 31 * result + (boost != +0.0f ? Float.floatToIntBits(boost) : 0);
result = 31 * result + (defaultOperator != null ? defaultOperator.hashCode() : 0);
result = 31 * result + (autoGeneratePhraseQueries ? 1 : 0);
result = 31 * result + (allowLeadingWildcard ? 1 : 0);
result = 31 * result + (lowercaseExpandedTerms ? 1 : 0);
result = 31 * result + (enablePositionIncrements ? 1 : 0);

View File

@ -83,6 +83,8 @@ public class FieldQueryParser extends AbstractIndexComponent implements XContent
qpSettings.enablePositionIncrements(parser.booleanValue());
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
qpSettings.allowLeadingWildcard(parser.booleanValue());
} else if ("auto_generate_phrase_queries".equals(currentFieldName) || "autoGeneratePhraseQueries".equals(currentFieldName)) {
qpSettings.autoGeneratePhraseQueries(parser.booleanValue());
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
qpSettings.lowercaseExpandedTerms(parser.booleanValue());
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {

View File

@ -137,6 +137,8 @@ public class QueryStringQueryParser extends AbstractIndexComponent implements XC
qpSettings.analyzer(analysisService.analyzer(parser.text()));
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
qpSettings.allowLeadingWildcard(parser.booleanValue());
} else if ("auto_generate_phrase_queries".equals(currentFieldName) || "autoGeneratePhraseQueries".equals(currentFieldName)) {
qpSettings.autoGeneratePhraseQueries(parser.booleanValue());
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
qpSettings.lowercaseExpandedTerms(parser.booleanValue());
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {