Search in sources :

Example 1 with ContextIndexSearcher

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

the class GlobalOrdinalsSignificantTermsAggregator method buildEmptyAggregation.

@Override
public SignificantStringTerms buildEmptyAggregation() {
    // We need to account for the significance of a miss in our global stats - provide corpus size as context
    ContextIndexSearcher searcher = context.searcher();
    IndexReader topReader = searcher.getIndexReader();
    int supersetSize = topReader.numDocs();
    return new SignificantStringTerms(name, bucketCountThresholds.getRequiredSize(), bucketCountThresholds.getMinDocCount(), pipelineAggregators(), metaData(), format, 0, supersetSize, significanceHeuristic, emptyList());
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexReader(org.apache.lucene.index.IndexReader)

Example 2 with ContextIndexSearcher

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

the class SignificantStringTermsAggregator method buildEmptyAggregation.

@Override
public SignificantStringTerms buildEmptyAggregation() {
    // We need to account for the significance of a miss in our global stats - provide corpus size as context
    ContextIndexSearcher searcher = context.searcher();
    IndexReader topReader = searcher.getIndexReader();
    int supersetSize = topReader.numDocs();
    return new SignificantStringTerms(name, bucketCountThresholds.getRequiredSize(), bucketCountThresholds.getMinDocCount(), pipelineAggregators(), metaData(), format, 0, supersetSize, significanceHeuristic, emptyList());
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexReader(org.apache.lucene.index.IndexReader)

Example 3 with ContextIndexSearcher

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

the class QueryProfilerTests method testApproximations.

public void testApproximations() throws IOException {
    QueryProfiler profiler = new QueryProfiler();
    Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader));
    // disable query caching since we want to test approximations, which won't
    // be exposed on a cached entry
    ContextIndexSearcher searcher = new ContextIndexSearcher(engineSearcher, null, MAYBE_CACHE_POLICY);
    searcher.setProfiler(profiler);
    Query query = new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random());
    searcher.count(query);
    List<ProfileResult> results = profiler.getTree();
    assertEquals(1, results.size());
    Map<String, Long> breakdown = results.get(0).getTimeBreakdown();
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString() + "_count").longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString() + "_count").longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString() + "_count").longValue(), greaterThan(0L));
    long rewriteTime = profiler.getRewriteTime();
    assertThat(rewriteTime, greaterThan(0L));
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) TermQuery(org.apache.lucene.search.TermQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) Term(org.apache.lucene.index.Term) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Engine(org.elasticsearch.index.engine.Engine)

Example 4 with ContextIndexSearcher

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

the class QueryProfilerTests method setup.

@BeforeClass
public static void setup() throws IOException {
    dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    final int numDocs = TestUtil.nextInt(random(), 1, 20);
    for (int i = 0; i < numDocs; ++i) {
        final int numHoles = random().nextInt(5);
        for (int j = 0; j < numHoles; ++j) {
            w.addDocument(new Document());
        }
        Document doc = new Document();
        doc.add(new StringField("foo", "bar", Store.NO));
        w.addDocument(doc);
    }
    reader = w.getReader();
    w.close();
    Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader));
    searcher = new ContextIndexSearcher(engineSearcher, IndexSearcher.getDefaultQueryCache(), MAYBE_CACHE_POLICY);
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) StringField(org.apache.lucene.document.StringField) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) Document(org.apache.lucene.document.Document) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Engine(org.elasticsearch.index.engine.Engine) BeforeClass(org.junit.BeforeClass)

Example 5 with ContextIndexSearcher

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

the class SignificantLongTermsAggregator method buildEmptyAggregation.

@Override
public SignificantLongTerms buildEmptyAggregation() {
    // We need to account for the significance of a miss in our global stats - provide corpus size as context
    ContextIndexSearcher searcher = context.searcher();
    IndexReader topReader = searcher.getIndexReader();
    int supersetSize = topReader.numDocs();
    return new SignificantLongTerms(name, bucketCountThresholds.getRequiredSize(), bucketCountThresholds.getMinDocCount(), pipelineAggregators(), metaData(), format, 0, supersetSize, significanceHeuristic, emptyList());
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexReader(org.apache.lucene.index.IndexReader)

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