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();
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations