Search in sources :

Example 16 with FunctionScoreQuery

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));
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) WeightFactorFunction(org.elasticsearch.common.lucene.search.function.WeightFactorFunction) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 17 with FunctionScoreQuery

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));
}
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 18 with FunctionScoreQuery

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

FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)18 FiltersFunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery)14 TermQuery (org.apache.lucene.search.TermQuery)13 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)9 Query (org.apache.lucene.search.Query)9 Term (org.apache.lucene.index.Term)8 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)5 WeightFactorFunction (org.elasticsearch.common.lucene.search.function.WeightFactorFunction)5 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)3 RandomScoreFunction (org.elasticsearch.common.lucene.search.function.RandomScoreFunction)3 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)2 BoostQuery (org.apache.lucene.search.BoostQuery)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 Explanation (org.apache.lucene.search.Explanation)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 Weight (org.apache.lucene.search.Weight)2 MultiPhrasePrefixQuery (org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery)2 CombineFunction (org.elasticsearch.common.lucene.search.function.CombineFunction)2 FieldValueFactorFunction (org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction)2