Search in sources :

Example 11 with FiltersFunctionScoreQuery

use of org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery in project elasticsearch by elastic.

the class FunctionScoreTests method testFilterFunctionScoreHashCodeAndEquals.

public void testFilterFunctionScoreHashCodeAndEquals() {
    ScoreMode mode = randomFrom(ScoreMode.values());
    CombineFunction combineFunction = randomFrom(CombineFunction.values());
    ScoreFunction scoreFunction = new DummyScoreFunction(combineFunction);
    Float minScore = randomBoolean() ? null : 1.0f;
    Float maxBoost = randomBoolean() ? Float.POSITIVE_INFINITY : randomFloat();
    FilterFunction function = new FilterFunction(new TermQuery(new Term("filter", "query")), scoreFunction);
    FiltersFunctionScoreQuery q = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, new FilterFunction[] { function }, maxBoost, minScore, combineFunction);
    FiltersFunctionScoreQuery q1 = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, new FilterFunction[] { function }, maxBoost, minScore, combineFunction);
    assertEquals(q, q);
    assertEquals(q.hashCode(), q.hashCode());
    assertEquals(q, q1);
    assertEquals(q.hashCode(), q1.hashCode());
    FiltersFunctionScoreQuery diffCombineFunc = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, new FilterFunction[] { function }, maxBoost, minScore, combineFunction == CombineFunction.AVG ? CombineFunction.MAX : CombineFunction.AVG);
    FiltersFunctionScoreQuery diffQuery = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "baz")), mode, new FilterFunction[] { function }, maxBoost, minScore, combineFunction);
    FiltersFunctionScoreQuery diffMode = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode == ScoreMode.AVG ? ScoreMode.FIRST : ScoreMode.AVG, new FilterFunction[] { function }, maxBoost, minScore, combineFunction);
    FiltersFunctionScoreQuery diffMaxBoost = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, new FilterFunction[] { function }, maxBoost == 1.0f ? 0.9f : 1.0f, minScore, combineFunction);
    FiltersFunctionScoreQuery diffMinScore = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, new FilterFunction[] { function }, maxBoost, minScore == null ? 0.9f : null, combineFunction);
    FilterFunction otherFunc = new FilterFunction(new TermQuery(new Term("filter", "other_query")), scoreFunction);
    FiltersFunctionScoreQuery diffFunc = new FiltersFunctionScoreQuery(new TermQuery(new Term("foo", "bar")), mode, randomBoolean() ? new FilterFunction[] { function, otherFunc } : new FilterFunction[] { otherFunc }, maxBoost, minScore, combineFunction);
    FiltersFunctionScoreQuery[] queries = new FiltersFunctionScoreQuery[] { diffQuery, diffMaxBoost, diffMinScore, diffMode, diffFunc, q, diffCombineFunc };
    final int numIters = randomIntBetween(20, 100);
    for (int i = 0; i < numIters; i++) {
        FiltersFunctionScoreQuery left = randomFrom(queries);
        FiltersFunctionScoreQuery right = randomFrom(queries);
        if (left == right) {
            assertEquals(left, right);
            assertEquals(left.hashCode(), right.hashCode());
        } else {
            assertNotEquals(left + " == " + right, left, right);
        }
    }
}
Also used : CombineFunction(org.elasticsearch.common.lucene.search.function.CombineFunction) ScoreMode(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery.ScoreMode) TermQuery(org.apache.lucene.search.TermQuery) FilterFunction(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery.FilterFunction) FiltersFunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery) Term(org.apache.lucene.index.Term) ScoreFunction(org.elasticsearch.common.lucene.search.function.ScoreFunction) LeafScoreFunction(org.elasticsearch.common.lucene.search.function.LeafScoreFunction) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction)

Aggregations

FiltersFunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery)11 TermQuery (org.apache.lucene.search.TermQuery)9 FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)8 Term (org.apache.lucene.index.Term)7 Query (org.apache.lucene.search.Query)6 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)5 FilterFunction (org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery.FilterFunction)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 CombineFunction (org.elasticsearch.common.lucene.search.function.CombineFunction)3 Explanation (org.apache.lucene.search.Explanation)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 TopDocs (org.apache.lucene.search.TopDocs)2 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)2 MultiPhrasePrefixQuery (org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery)2 ScoreMode (org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery.ScoreMode)2 ScoreFunction (org.elasticsearch.common.lucene.search.function.ScoreFunction)2 WeightFactorFunction (org.elasticsearch.common.lucene.search.function.WeightFactorFunction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1