use of org.elasticsearch.common.lucene.search.function.FunctionScoreQuery in project elasticsearch by elastic.
the class FunctionScoreTests method testWeightOnlyCreatesBoostFunction.
public void testWeightOnlyCreatesBoostFunction() throws IOException {
FunctionScoreQuery filtersFunctionScoreQueryWithWeights = new FunctionScoreQuery(new MatchAllDocsQuery(), new WeightFactorFunction(2), 0.0f, CombineFunction.MULTIPLY, 100);
TopDocs topDocsWithWeights = searcher.search(filtersFunctionScoreQueryWithWeights, 1);
float score = topDocsWithWeights.scoreDocs[0].score;
assertThat(score, equalTo(2.0f));
}
use of org.elasticsearch.common.lucene.search.function.FunctionScoreQuery in project elasticsearch by elastic.
the class FunctionScoreQueryBuilderTests method testCustomWeightFactorQueryBuilderWithFunctionScoreWithoutQueryGiven.
public void testCustomWeightFactorQueryBuilderWithFunctionScoreWithoutQueryGiven() throws IOException {
Query parsedQuery = parseQuery(functionScoreQuery(weightFactorFunction(1.3f))).toQuery(createShardContext());
assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class));
FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery;
assertThat(functionScoreQuery.getSubQuery() instanceof MatchAllDocsQuery, equalTo(true));
assertThat((double) ((WeightFactorFunction) functionScoreQuery.getFunction()).getWeight(), closeTo(1.3, 0.001));
}
use of org.elasticsearch.common.lucene.search.function.FunctionScoreQuery in project elasticsearch by elastic.
the class FunctionScoreQueryBuilderTests method testCustomWeightFactorQueryBuilderWithFunctionScore.
public void testCustomWeightFactorQueryBuilderWithFunctionScore() throws IOException {
Query parsedQuery = parseQuery(functionScoreQuery(termQuery("name.last", "banon"), weightFactorFunction(1.3f))).toQuery(createShardContext());
assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class));
FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery;
assertThat(((TermQuery) functionScoreQuery.getSubQuery()).getTerm(), equalTo(new Term("name.last", "banon")));
assertThat((double) ((WeightFactorFunction) functionScoreQuery.getFunction()).getWeight(), closeTo(1.3, 0.001));
}
Aggregations