add additional method for setting combine mode with CombineFunction parameter

This commit is contained in:
Britta Weber 2013-08-23 14:00:44 +02:00
parent 8d6dc5908e
commit 8b9396b6da
2 changed files with 12 additions and 6 deletions

View File

@ -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;

View File

@ -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)));