Search in sources :

Example 26 with FunctionScoreQuery

use of org.opensearch.common.lucene.search.function.FunctionScoreQuery in project OpenSearch by opensearch-project.

the class FunctionScoreTests method getFunctionScoreExplanation.

public Explanation getFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction scoreFunction) throws IOException {
    FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(new TermQuery(TERM), scoreFunction, CombineFunction.AVG, 0.0f, 100);
    Weight weight = searcher.createWeight(searcher.rewrite(functionScoreQuery), org.apache.lucene.search.ScoreMode.COMPLETE, 1f);
    Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0);
    return explanation.getDetails()[1];
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) FunctionScoreQuery(org.opensearch.common.lucene.search.function.FunctionScoreQuery) Explanation(org.apache.lucene.search.Explanation) Weight(org.apache.lucene.search.Weight)

Example 27 with FunctionScoreQuery

use of org.opensearch.common.lucene.search.function.FunctionScoreQuery in project OpenSearch by opensearch-project.

the class DiversifiedSamplerTests method testCase.

private void testCase(IndexSearcher indexSearcher, MappedFieldType genreFieldType, String executionHint, Consumer<InternalSampler> verify, int shardSize, int maxDocsPerValue) throws IOException {
    MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType("id");
    SortedNumericIndexFieldData fieldData = new SortedNumericIndexFieldData("price", IndexNumericFieldData.NumericType.DOUBLE);
    FunctionScoreQuery query = new FunctionScoreQuery(new MatchAllDocsQuery(), new FieldValueFactorFunction("price", 1, FieldValueFactorFunction.Modifier.RECIPROCAL, null, fieldData));
    DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name").field(genreFieldType.name()).executionHint(executionHint).maxDocsPerValue(maxDocsPerValue).shardSize(shardSize).subAggregation(new TermsAggregationBuilder("terms").field("id"));
    InternalSampler result = searchAndReduce(indexSearcher, query, builder, genreFieldType, idFieldType);
    verify.accept(result);
}
Also used : SortedNumericIndexFieldData(org.opensearch.index.fielddata.plain.SortedNumericIndexFieldData) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) FunctionScoreQuery(org.opensearch.common.lucene.search.function.FunctionScoreQuery) FieldValueFactorFunction(org.opensearch.common.lucene.search.function.FieldValueFactorFunction) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

FunctionScoreQuery (org.opensearch.common.lucene.search.function.FunctionScoreQuery)27 TermQuery (org.apache.lucene.search.TermQuery)21 Term (org.apache.lucene.index.Term)15 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)13 Query (org.apache.lucene.search.Query)12 IndexSearcher (org.apache.lucene.search.IndexSearcher)9 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)8 RandomScoreFunction (org.opensearch.common.lucene.search.function.RandomScoreFunction)8 ScoreFunction (org.opensearch.common.lucene.search.function.ScoreFunction)6 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)5 FieldValueFactorFunction (org.opensearch.common.lucene.search.function.FieldValueFactorFunction)5 FilterScoreFunction (org.opensearch.common.lucene.search.function.FunctionScoreQuery.FilterScoreFunction)5 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)4 TopDocs (org.apache.lucene.search.TopDocs)4 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)4 CombineFunction (org.opensearch.common.lucene.search.function.CombineFunction)4 LeafScoreFunction (org.opensearch.common.lucene.search.function.LeafScoreFunction)4 WeightFactorFunction (org.opensearch.common.lucene.search.function.WeightFactorFunction)4 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)3 Explanation (org.apache.lucene.search.Explanation)3