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": {
|
"custom_filters_score": {
|
||||||
"filters": [
|
"filters": [
|
||||||
{
|
{
|
||||||
"boost": "3",
|
"boost_factor": "3",
|
||||||
"filter": {...}
|
"filter": {...}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -472,7 +472,7 @@ becomes:
|
||||||
"function_score": {
|
"function_score": {
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"boost": "3",
|
"boost_factor": "3",
|
||||||
"filter": {...}
|
"filter": {...}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@ public enum CombineFunction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "mult";
|
return "multiply";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query.functionscore;
|
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.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
|
@ -55,6 +57,17 @@ public class FunctionScoreQueryParser implements QueryParser {
|
||||||
return new String[] { NAME, Strings.toCamelCase(NAME) };
|
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
|
@Override
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
@ -179,11 +192,10 @@ public class FunctionScoreQueryParser implements QueryParser {
|
||||||
|
|
||||||
private CombineFunction parseBoostMode(QueryParseContext parseContext, XContentParser parser) throws IOException {
|
private CombineFunction parseBoostMode(QueryParseContext parseContext, XContentParser parser) throws IOException {
|
||||||
String boostMode = parser.text();
|
String boostMode = parser.text();
|
||||||
for (CombineFunction cf : CombineFunction.values()) {
|
CombineFunction cf = combineFunctionsMap.get(boostMode);
|
||||||
if (cf.getName().equals(boostMode)) {
|
if (cf == null) {
|
||||||
return cf;
|
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