use of org.elasticsearch.common.lucene.search.function.WeightFactorFunction in project elasticsearch by elastic.
the class FunctionScoreTests method testWeightFactorNeedsScore.
public void testWeightFactorNeedsScore() {
for (boolean needsScore : new boolean[] { true, false }) {
WeightFactorFunction function = new WeightFactorFunction(10.0f, new ScoreFunction(CombineFunction.REPLACE) {
@Override
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) throws IOException {
return null;
}
@Override
public boolean needsScores() {
return needsScore;
}
@Override
protected boolean doEquals(ScoreFunction other) {
return false;
}
@Override
protected int doHashCode() {
return 0;
}
});
assertEquals(needsScore, function.needsScores());
}
}
use of org.elasticsearch.common.lucene.search.function.WeightFactorFunction 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.WeightFactorFunction 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