Search in sources :

Example 1 with RandomScoreFunction

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

the class QueryAnalyzerTests method testFunctionScoreQuery.

public void testFunctionScoreQuery() {
    TermQuery termQuery = new TermQuery(new Term("_field", "_value"));
    FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(termQuery, new RandomScoreFunction());
    Result result = analyze(functionScoreQuery);
    assertThat(result.verified, is(true));
    assertTermsEqual(result.terms, new Term("_field", "_value"));
    functionScoreQuery = new FunctionScoreQuery(termQuery, new RandomScoreFunction(), 1f, null, 10f);
    result = analyze(functionScoreQuery);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, new Term("_field", "_value"));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) TermQuery(org.apache.lucene.search.TermQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 2 with RandomScoreFunction

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

the class RandomScoreFunctionBuilder method doToFunction.

@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    final MappedFieldType fieldType = context.getMapperService().fullName("_uid");
    if (fieldType == null) {
        // mapper could be null if we are on a shard with no docs yet, so this won't actually be used
        return new RandomScoreFunction();
    }
    final int salt = (context.index().getName().hashCode() << 10) | context.getShardId();
    final IndexFieldData<?> uidFieldData = context.getForField(fieldType);
    return new RandomScoreFunction(this.seed == null ? hash(context.nowInMillis()) : seed, salt, uidFieldData);
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction)

Example 3 with RandomScoreFunction

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

the class PercolatorHighlightSubFetchPhaseTests method testLocatePercolatorQuery.

public void testLocatePercolatorQuery() {
    PercolateQuery percolateQuery = new PercolateQuery("", ctx -> null, new BytesArray("{}"), new MatchAllDocsQuery(), Mockito.mock(IndexSearcher.class), new MatchAllDocsQuery());
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(new MatchAllDocsQuery()), nullValue());
    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.FILTER);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(bq.build()), nullValue());
    bq.add(percolateQuery, BooleanClause.Occur.FILTER);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(bq.build()), sameInstance(percolateQuery));
    ConstantScoreQuery constantScoreQuery = new ConstantScoreQuery(new MatchAllDocsQuery());
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(constantScoreQuery), nullValue());
    constantScoreQuery = new ConstantScoreQuery(percolateQuery);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(constantScoreQuery), sameInstance(percolateQuery));
    BoostQuery boostQuery = new BoostQuery(new MatchAllDocsQuery(), 1f);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(boostQuery), nullValue());
    boostQuery = new BoostQuery(percolateQuery, 1f);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(boostQuery), sameInstance(percolateQuery));
    FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(new MatchAllDocsQuery(), new RandomScoreFunction());
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(functionScoreQuery), nullValue());
    functionScoreQuery = new FunctionScoreQuery(percolateQuery, new RandomScoreFunction());
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(functionScoreQuery), sameInstance(percolateQuery));
    DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery(Arrays.asList(new MatchAllDocsQuery()), 1f);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(disjunctionMaxQuery), nullValue());
    disjunctionMaxQuery = new DisjunctionMaxQuery(Arrays.asList(percolateQuery, new MatchAllDocsQuery()), 1f);
    assertThat(PercolatorHighlightSubFetchPhase.locatePercolatorQuery(disjunctionMaxQuery), sameInstance(percolateQuery));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) BooleanQuery(org.apache.lucene.search.BooleanQuery) BytesArray(org.elasticsearch.common.bytes.BytesArray) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction)

Aggregations

RandomScoreFunction (org.elasticsearch.common.lucene.search.function.RandomScoreFunction)3 FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)2 Term (org.apache.lucene.index.Term)1 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1 Result (org.elasticsearch.percolator.QueryAnalyzer.Result)1 QueryAnalyzer.selectTermListWithTheLongestShortestTerm (org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm)1