Search in sources :

Example 36 with LeafReaderContext

use of org.apache.lucene.index.LeafReaderContext in project crate by crate.

the class FetchCollector method collect.

public StreamBucket collect(IntContainer docIds) throws IOException {
    StreamBucket.Builder builder = new StreamBucket.Builder(streamers);
    for (IntCursor cursor : docIds) {
        int docId = cursor.value;
        int readerIndex = ReaderUtil.subIndex(docId, readerContexts);
        LeafReaderContext subReaderContext = readerContexts.get(readerIndex);
        setNextDocId(subReaderContext, docId - subReaderContext.docBase);
        builder.add(row);
    }
    return builder.build();
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) StreamBucket(io.crate.executor.transport.StreamBucket)

Example 37 with LeafReaderContext

use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testEmptyLong.

public void testEmptyLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "long", null, 42, null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 38 with LeafReaderContext

use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testEmptyKeyword.

public void testEmptyKeyword() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(context, null, "bytes", null, null, null, null);
        ValuesSource.Bytes valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "bytes", null, "abc", null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(new BytesRef("abc"), values.valueAt(0));
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 39 with LeafReaderContext

use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testUnmappedLong.

public void testUnmappedLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        assertNull(valuesSource);
        config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "long", null, 42, null, null);
        valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 40 with LeafReaderContext

use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testKeyword.

public void testKeyword() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword");
    client().prepareIndex("index", "type", "1").setSource("bytes", "abc").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(context, null, "bytes", null, null, null, null);
        ValuesSource.Bytes valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(new BytesRef("abc"), values.valueAt(0));
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Aggregations

LeafReaderContext (org.apache.lucene.index.LeafReaderContext)335 LeafReader (org.apache.lucene.index.LeafReader)73 Document (org.apache.lucene.document.Document)71 IOException (java.io.IOException)69 BytesRef (org.apache.lucene.util.BytesRef)67 Directory (org.apache.lucene.store.Directory)61 Term (org.apache.lucene.index.Term)52 IndexSearcher (org.apache.lucene.search.IndexSearcher)49 IndexReader (org.apache.lucene.index.IndexReader)48 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)45 DirectoryReader (org.apache.lucene.index.DirectoryReader)44 Bits (org.apache.lucene.util.Bits)44 NumericDocValues (org.apache.lucene.index.NumericDocValues)43 ArrayList (java.util.ArrayList)41 Weight (org.apache.lucene.search.Weight)37 Terms (org.apache.lucene.index.Terms)36 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)36 Scorer (org.apache.lucene.search.Scorer)36 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)34 Query (org.apache.lucene.search.Query)34