From 8b9396b6da2e5b8a72ce6a820973cc69f5bd395f Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Fri, 23 Aug 2013 14:00:44 +0200 Subject: [PATCH] add additional method for setting combine mode with CombineFunction parameter --- .../functionscore/FunctionScoreQueryBuilder.java | 6 ++++++ .../functionscore/DecayFunctionScoreTests.java | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index 61601c6cb76..e013ab3f9ef 100644 --- a/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.query.functionscore; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.BaseQueryBuilder; import org.elasticsearch.index.query.BoostableQueryBuilder; @@ -81,6 +82,11 @@ public class FunctionScoreQueryBuilder extends BaseQueryBuilder implements Boost this.boostMode = boostMode; return this; } + + public FunctionScoreQueryBuilder boostMode(CombineFunction combineFunction) { + this.boostMode = combineFunction.getName(); + return this; + } public FunctionScoreQueryBuilder maxBoost(float maxBoost) { this.maxBoost = maxBoost; diff --git a/src/test/java/org/elasticsearch/test/integration/search/functionscore/DecayFunctionScoreTests.java b/src/test/java/org/elasticsearch/test/integration/search/functionscore/DecayFunctionScoreTests.java index c2ac7c97b27..1f288c21e58 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/functionscore/DecayFunctionScoreTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/functionscore/DecayFunctionScoreTests.java @@ -345,7 +345,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.MULT.getName())))); + 2.0f).boostMode(CombineFunction.MULT)))); SearchResponse sr = response.actionGet(); SearchHits sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1))); @@ -357,7 +357,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.REPLACE.getName())))); + 2.0f).boostMode(CombineFunction.REPLACE)))); sr = response.actionGet(); sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1))); @@ -369,7 +369,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.SUM.getName())))); + 2.0f).boostMode(CombineFunction.SUM)))); sr = response.actionGet(); sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1))); @@ -381,7 +381,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.AVG.getName())))); + 2.0f).boostMode(CombineFunction.AVG)))); sr = response.actionGet(); sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1))); @@ -393,7 +393,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.MIN.getName())))); + 2.0f).boostMode(CombineFunction.MIN)))); sr = response.actionGet(); sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1))); @@ -405,7 +405,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest { searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(true).query( functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost( - 2.0f).boostMode(CombineFunction.MAX.getName())))); + 2.0f).boostMode(CombineFunction.MAX)))); sr = response.actionGet(); sh = sr.getHits(); assertThat(sh.getTotalHits(), equalTo((long) (1)));