add additional method for setting combine mode with CombineFunction parameter
This commit is contained in:
parent
8d6dc5908e
commit
8b9396b6da
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.index.query.functionscore;
|
package org.elasticsearch.index.query.functionscore;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
|
import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.query.BaseQueryBuilder;
|
import org.elasticsearch.index.query.BaseQueryBuilder;
|
||||||
import org.elasticsearch.index.query.BoostableQueryBuilder;
|
import org.elasticsearch.index.query.BoostableQueryBuilder;
|
||||||
|
@ -82,6 +83,11 @@ public class FunctionScoreQueryBuilder extends BaseQueryBuilder implements Boost
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FunctionScoreQueryBuilder boostMode(CombineFunction combineFunction) {
|
||||||
|
this.boostMode = combineFunction.getName();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public FunctionScoreQueryBuilder maxBoost(float maxBoost) {
|
public FunctionScoreQueryBuilder maxBoost(float maxBoost) {
|
||||||
this.maxBoost = maxBoost;
|
this.maxBoost = maxBoost;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -345,7 +345,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
SearchResponse sr = response.actionGet();
|
||||||
SearchHits sh = sr.getHits();
|
SearchHits sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
@ -357,7 +357,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
sr = response.actionGet();
|
||||||
sh = sr.getHits();
|
sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
@ -369,7 +369,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
sr = response.actionGet();
|
||||||
sh = sr.getHits();
|
sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
@ -381,7 +381,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
sr = response.actionGet();
|
||||||
sh = sr.getHits();
|
sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
@ -393,7 +393,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
sr = response.actionGet();
|
||||||
sh = sr.getHits();
|
sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
@ -405,7 +405,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
|
||||||
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(true).query(
|
searchSource().explain(true).query(
|
||||||
functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 0.0, 1.0).setDecay(0.5)).boost(
|
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();
|
sr = response.actionGet();
|
||||||
sh = sr.getHits();
|
sh = sr.getHits();
|
||||||
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
assertThat(sh.getTotalHits(), equalTo((long) (1)));
|
||||||
|
|
Loading…
Reference in New Issue