List of usage examples for org.apache.lucene.index PointValues getBytesPerDimension
public abstract int getBytesPerDimension() throws IOException;
From source file:org.elasticsearch.search.aggregations.bucket.composite.PointsSortedDocsProducer.java
License:Apache License
@Override
DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context,
boolean fillDocIdSet) throws IOException {
final PointValues values = context.reader().getPointValues(field);
if (values == null) {
// no value for the field
return DocIdSet.EMPTY;
}// w ww.j a v a2 s .c om
long lowerBucket = Long.MIN_VALUE;
Comparable<?> lowerValue = queue.getLowerValueLeadSource();
if (lowerValue != null) {
if (lowerValue.getClass() != Long.class) {
throw new IllegalStateException("expected Long, got " + lowerValue.getClass());
}
lowerBucket = (Long) lowerValue;
}
long upperBucket = Long.MAX_VALUE;
Comparable<?> upperValue = queue.getUpperValueLeadSource();
if (upperValue != null) {
if (upperValue.getClass() != Long.class) {
throw new IllegalStateException("expected Long, got " + upperValue.getClass());
}
upperBucket = (Long) upperValue;
}
DocIdSetBuilder builder = fillDocIdSet ? new DocIdSetBuilder(context.reader().maxDoc(), values, field)
: null;
Visitor visitor = new Visitor(context, queue, builder, values.getBytesPerDimension(), lowerBucket,
upperBucket);
try {
values.intersect(visitor);
visitor.flush();
} catch (CollectionTerminatedException exc) {
}
return fillDocIdSet ? builder.build() : DocIdSet.EMPTY;
}
From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReaderTests.java
License:Open Source License
/** * test filtering two int points//w w w .ja v a 2 s . c o m */ public void testPoints() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(null); IndexWriter iw = new IndexWriter(dir, iwc); // add document with 2 points Document doc = new Document(); doc.add(new IntPoint("fieldA", 1)); doc.add(new IntPoint("fieldB", 2)); iw.addDocument(doc); // open reader DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), new CharacterRunAutomaton(Automata.makeString("fieldA"))); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); PointValues points = segmentReader.getPointValues("fieldA"); assertNull(segmentReader.getPointValues("fieldB")); // size statistic assertEquals(1, points.size()); // doccount statistic assertEquals(1, points.getDocCount()); // min statistic assertNotNull(points.getMinPackedValue()); // max statistic assertNotNull(points.getMaxPackedValue()); // bytes per dimension assertEquals(Integer.BYTES, points.getBytesPerDimension()); // number of dimensions assertEquals(1, points.getNumDimensions()); // walk the trees: we should see stuff in fieldA AtomicBoolean sawDoc = new AtomicBoolean(false); points.intersect(new IntersectVisitor() { @Override public void visit(int docID) throws IOException { throw new IllegalStateException("should not get here"); } @Override public void visit(int docID, byte[] packedValue) throws IOException { sawDoc.set(true); } @Override public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { return Relation.CELL_CROSSES_QUERY; } }); assertTrue(sawDoc.get()); TestUtil.checkReader(ir); IOUtils.close(ir, iw, dir); }