use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.
the class ValuesSourceConfigTests method testBoolean.
public void testBoolean() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bool", "type=boolean");
client().prepareIndex("index", "type", "1").setSource("bool", true).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, "bool", 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(1, values.count());
assertEquals(1, values.valueAt(0));
}
}
use of org.apache.lucene.index.LeafReaderContext in project elasticsearch by elastic.
the class ValuesSourceConfigTests method testUnmappedKeyword.
public void testUnmappedKeyword() 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.Bytes> config = ValuesSourceConfig.resolve(context, ValueType.STRING, "bytes", null, null, null, null);
ValuesSource.Bytes valuesSource = config.toValuesSource(context);
assertNull(valuesSource);
config = ValuesSourceConfig.resolve(context, ValueType.STRING, "bytes", null, "abc", null, null);
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));
}
}
use of org.apache.lucene.index.LeafReaderContext in project neo4j by neo4j.
the class DocValuesCollector method getSortedValuesIterator.
/**
* @param field the field that contains the values
* @param sort how the results should be sorted
* @return an iterator over all NumericDocValues from the given field with respect to the given sort
* @throws IOException
*/
public ValuesIterator getSortedValuesIterator(String field, Sort sort) throws IOException {
if (sort == null || sort == Sort.INDEXORDER) {
return getValuesIterator(field);
}
int size = getTotalHits();
if (size == 0) {
return ValuesIterator.EMPTY;
}
TopDocs topDocs = getTopDocs(sort, size);
LeafReaderContext[] contexts = getLeafReaderContexts(getMatchingDocs());
return new TopDocsValuesIterator(topDocs, contexts, field);
}
use of org.apache.lucene.index.LeafReaderContext in project lucene-solr by apache.
the class TestSuggestField method testSuggestOnAllFilteredDocuments.
@Test
public void testSuggestOnAllFilteredDocuments() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
int num = Math.min(1000, atLeast(10));
for (int i = 0; i < num; i++) {
Document document = new Document();
document.add(new SuggestField("suggest_field", "abc_" + i, i));
document.add(newStringField("str_fld", "deleted", Field.Store.NO));
iw.addDocument(document);
if (usually()) {
iw.commit();
}
}
BitsProducer filter = new BitsProducer() {
@Override
public Bits getBits(LeafReaderContext context) throws IOException {
return new Bits.MatchNoBits(context.reader().maxDoc());
}
};
DirectoryReader reader = iw.getReader();
SuggestIndexSearcher indexSearcher = new SuggestIndexSearcher(reader);
// no random access required;
// calling suggest with filter that does not match any documents should early terminate
PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "abc_"), filter);
TopSuggestDocs suggest = indexSearcher.suggest(query, num, false);
assertThat(suggest.totalHits, equalTo(0));
reader.close();
iw.close();
}
use of org.apache.lucene.index.LeafReaderContext in project lucene-solr by apache.
the class TestUtil method addIndexesSlowly.
public static void addIndexesSlowly(IndexWriter writer, DirectoryReader... readers) throws IOException {
List<CodecReader> leaves = new ArrayList<>();
for (DirectoryReader reader : readers) {
for (LeafReaderContext context : reader.leaves()) {
leaves.add(SlowCodecReaderWrapper.wrap(context.reader()));
}
}
writer.addIndexes(leaves.toArray(new CodecReader[leaves.size()]));
}
Aggregations