Search in sources :

Example 6 with ContextIndexSearcher

use of org.elasticsearch.search.internal.ContextIndexSearcher in project elasticsearch by elastic.

the class QueryRescorer method explain.

@Override
public Explanation explain(int topLevelDocId, SearchContext context, RescoreSearchContext rescoreContext, Explanation sourceExplanation) throws IOException {
    QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
    ContextIndexSearcher searcher = context.searcher();
    if (sourceExplanation == null) {
        // this should not happen but just in case
        return Explanation.noMatch("nothing matched");
    }
    // TODO: this isn't right?  I.e., we are incorrectly pretending all first pass hits were rescored?  If the requested docID was
    // beyond the top rescoreContext.window() in the first pass hits, we don't rescore it now?
    Explanation rescoreExplain = searcher.explain(rescore.query(), topLevelDocId);
    float primaryWeight = rescore.queryWeight();
    Explanation prim;
    if (sourceExplanation.isMatch()) {
        prim = Explanation.match(sourceExplanation.getValue() * primaryWeight, "product of:", sourceExplanation, Explanation.match(primaryWeight, "primaryWeight"));
    } else {
        prim = Explanation.noMatch("First pass did not match", sourceExplanation);
    }
    // we should add QueryRescorer.explainCombine to Lucene?
    if (rescoreExplain != null && rescoreExplain.isMatch()) {
        float secondaryWeight = rescore.rescoreQueryWeight();
        Explanation sec = Explanation.match(rescoreExplain.getValue() * secondaryWeight, "product of:", rescoreExplain, Explanation.match(secondaryWeight, "secondaryWeight"));
        QueryRescoreMode scoreMode = rescore.scoreMode();
        return Explanation.match(scoreMode.combine(prim.getValue(), sec.getValue()), scoreMode + " of:", prim, sec);
    } else {
        return prim;
    }
}
Also used : Explanation(org.apache.lucene.search.Explanation) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher)

Example 7 with ContextIndexSearcher

use of org.elasticsearch.search.internal.ContextIndexSearcher in project elasticsearch by elastic.

the class AggregatorTestCase method createSearchContext.

protected SearchContext createSearchContext(IndexSearcher indexSearcher, IndexSettings indexSettings) {
    Engine.Searcher searcher = new Engine.Searcher("aggregator_test", indexSearcher);
    QueryCache queryCache = new DisabledQueryCache(indexSettings);
    QueryCachingPolicy queryCachingPolicy = new QueryCachingPolicy() {

        @Override
        public void onUse(Query query) {
        }

        @Override
        public boolean shouldCache(Query query) throws IOException {
            // never cache a query
            return false;
        }
    };
    ContextIndexSearcher contextIndexSearcher = new ContextIndexSearcher(searcher, queryCache, queryCachingPolicy);
    SearchContext searchContext = mock(SearchContext.class);
    when(searchContext.numberOfShards()).thenReturn(1);
    when(searchContext.searcher()).thenReturn(contextIndexSearcher);
    when(searchContext.fetchPhase()).thenReturn(new FetchPhase(Arrays.asList(new FetchSourceSubPhase(), new DocValueFieldsFetchSubPhase())));
    doAnswer(invocation -> {
        releasables.add((Releasable) invocation.getArguments()[0]);
        return null;
    }).when(searchContext).addReleasable(anyObject(), anyObject());
    return searchContext;
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) QueryCache(org.apache.lucene.search.QueryCache) Query(org.apache.lucene.search.Query) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) FetchPhase(org.elasticsearch.search.fetch.FetchPhase) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) SearchContext(org.elasticsearch.search.internal.SearchContext) Engine(org.elasticsearch.index.engine.Engine) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) FetchSourceSubPhase(org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase) DocValueFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase)

Aggregations

ContextIndexSearcher (org.elasticsearch.search.internal.ContextIndexSearcher)7 IndexReader (org.apache.lucene.index.IndexReader)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 Engine (org.elasticsearch.index.engine.Engine)3 Query (org.apache.lucene.search.Query)2 Document (org.apache.lucene.document.Document)1 StringField (org.apache.lucene.document.StringField)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 Term (org.apache.lucene.index.Term)1 Explanation (org.apache.lucene.search.Explanation)1 QueryCache (org.apache.lucene.search.QueryCache)1 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)1 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)1 FetchPhase (org.elasticsearch.search.fetch.FetchPhase)1 DocValueFieldsFetchSubPhase (org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase)1 FetchSourceSubPhase (org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase)1 SearchContext (org.elasticsearch.search.internal.SearchContext)1 ProfileResult (org.elasticsearch.search.profile.ProfileResult)1