From 34441f3897560e9d39517676918042784694176a Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Thu, 10 Oct 2013 21:08:12 +0200 Subject: [PATCH] fix naming in function_score - "boost" should be "boost_factor" - "mult" should be "multiply" Also, store combine function names in ImmutableMap instead of iterating over all possible names each time. closes #3872 for master --- .../queries/function-score-query.asciidoc | 4 ++-- .../search/function/CombineFunction.java | 2 +- .../FunctionScoreQueryParser.java | 22 ++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/reference/query-dsl/queries/function-score-query.asciidoc b/docs/reference/query-dsl/queries/function-score-query.asciidoc index 87b6c4dcdea..c1234ecd12a 100644 --- a/docs/reference/query-dsl/queries/function-score-query.asciidoc +++ b/docs/reference/query-dsl/queries/function-score-query.asciidoc @@ -448,7 +448,7 @@ and the <> "custom_filters_score": { "filters": [ { - "boost": "3", + "boost_factor": "3", "filter": {...} }, { @@ -472,7 +472,7 @@ becomes: "function_score": { "functions": [ { - "boost": "3", + "boost_factor": "3", "filter": {...} }, { diff --git a/src/main/java/org/elasticsearch/common/lucene/search/function/CombineFunction.java b/src/main/java/org/elasticsearch/common/lucene/search/function/CombineFunction.java index e51601f545b..1f4e547181e 100644 --- a/src/main/java/org/elasticsearch/common/lucene/search/function/CombineFunction.java +++ b/src/main/java/org/elasticsearch/common/lucene/search/function/CombineFunction.java @@ -31,7 +31,7 @@ public enum CombineFunction { @Override public String getName() { - return "mult"; + return "multiply"; } @Override diff --git a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java index d0a05fec16c..e5aa6dce14b 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.query.functionscore; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.elasticsearch.common.Strings; @@ -54,6 +56,17 @@ public class FunctionScoreQueryParser implements QueryParser { public String[] names() { return new String[] { NAME, Strings.toCamelCase(NAME) }; } + + private static final ImmutableMap combineFunctionsMap; + + static { + CombineFunction[] values = CombineFunction.values(); + Builder combineFunctionMapBuilder = ImmutableMap.builder(); + for (CombineFunction combineFunction : values) { + combineFunctionMapBuilder.put(combineFunction.getName(), combineFunction); + } + combineFunctionsMap = combineFunctionMapBuilder.build(); + } @Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { @@ -179,11 +192,10 @@ public class FunctionScoreQueryParser implements QueryParser { private CombineFunction parseBoostMode(QueryParseContext parseContext, XContentParser parser) throws IOException { String boostMode = parser.text(); - for (CombineFunction cf : CombineFunction.values()) { - if (cf.getName().equals(boostMode)) { - return cf; - } + CombineFunction cf = combineFunctionsMap.get(boostMode); + if (cf == null) { + throw new QueryParsingException(parseContext.index(), NAME + " illegal boost_mode [" + boostMode + "]"); } - throw new QueryParsingException(parseContext.index(), NAME + " illegal boost_mode [" + boostMode + "]"); + return cf; } } \ No newline at end of file