Search in sources :

Example 6 with WeightFactorFunction

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());
    }
}
Also used : WeightFactorFunction(org.elasticsearch.common.lucene.search.function.WeightFactorFunction) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) IOException(java.io.IOException) LeafScoreFunction(org.elasticsearch.common.lucene.search.function.LeafScoreFunction) ScoreFunction(org.elasticsearch.common.lucene.search.function.ScoreFunction) LeafScoreFunction(org.elasticsearch.common.lucene.search.function.LeafScoreFunction) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction)

Example 7 with WeightFactorFunction

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));
}
Also used : WeightFactorFunction(org.elasticsearch.common.lucene.search.function.WeightFactorFunction) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) QueryBuilders.functionScoreQuery(org.elasticsearch.index.query.QueryBuilders.functionScoreQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) TermQuery(org.apache.lucene.search.TermQuery) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 8 with WeightFactorFunction

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));
}
Also used : WeightFactorFunction(org.elasticsearch.common.lucene.search.function.WeightFactorFunction) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) QueryBuilders.functionScoreQuery(org.elasticsearch.index.query.QueryBuilders.functionScoreQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) TermQuery(org.apache.lucene.search.TermQuery) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) Term(org.apache.lucene.index.Term)

Aggregations

WeightFactorFunction (org.elasticsearch.common.lucene.search.function.WeightFactorFunction)8 FiltersFunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery)6 FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4 Query (org.apache.lucene.search.Query)3 TopDocs (org.apache.lucene.search.TopDocs)3 QueryBuilders.functionScoreQuery (org.elasticsearch.index.query.QueryBuilders.functionScoreQuery)3 QueryBuilders.matchAllQuery (org.elasticsearch.index.query.QueryBuilders.matchAllQuery)3 QueryBuilders.termQuery (org.elasticsearch.index.query.QueryBuilders.termQuery)3 IOException (java.io.IOException)2 Term (org.apache.lucene.index.Term)2 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 UncheckedIOException (java.io.UncheckedIOException)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Explanation (org.apache.lucene.search.Explanation)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 CombineFunction (org.elasticsearch.common.lucene.search.function.CombineFunction)1 FieldValueFactorFunction (org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction)1