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
This commit is contained in:
parent
899189694f
commit
34441f3897
|
@ -448,7 +448,7 @@ and the <<query-dsl-custom-filters-score-query>>
|
|||
"custom_filters_score": {
|
||||
"filters": [
|
||||
{
|
||||
"boost": "3",
|
||||
"boost_factor": "3",
|
||||
"filter": {...}
|
||||
},
|
||||
{
|
||||
|
@ -472,7 +472,7 @@ becomes:
|
|||
"function_score": {
|
||||
"functions": [
|
||||
{
|
||||
"boost": "3",
|
||||
"boost_factor": "3",
|
||||
"filter": {...}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ public enum CombineFunction {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "mult";
|
||||
return "multiply";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
@ -55,6 +57,17 @@ public class FunctionScoreQueryParser implements QueryParser {
|
|||
return new String[] { NAME, Strings.toCamelCase(NAME) };
|
||||
}
|
||||
|
||||
private static final ImmutableMap<String, CombineFunction> combineFunctionsMap;
|
||||
|
||||
static {
|
||||
CombineFunction[] values = CombineFunction.values();
|
||||
Builder<String, CombineFunction> combineFunctionMapBuilder = ImmutableMap.<String, CombineFunction>builder();
|
||||
for (CombineFunction combineFunction : values) {
|
||||
combineFunctionMapBuilder.put(combineFunction.getName(), combineFunction);
|
||||
}
|
||||
combineFunctionsMap = combineFunctionMapBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue