Java Code Examples for org.apache.lucene.index.SortedNumericDocValues#nextValue()
The following examples show how to use
org.apache.lucene.index.SortedNumericDocValues#nextValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPrefixCompletionQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Bits getBits(final LeafReaderContext context) throws IOException { final int maxDoc = context.reader().maxDoc(); FixedBitSet bits = new FixedBitSet(maxDoc); final SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), field); int docID; while ((docID = values.nextDoc()) != NO_MORE_DOCS) { final int count = values.docValueCount(); for (int i = 0; i < count; ++i) { final long v = values.nextValue(); if (v >= min && v <= max) { bits.set(docID); break; } } } return bits; }
Example 2
Source File: Lucene80DocValuesConsumer.java From lucene-solr with Apache License 2.0 | 5 votes |
private void writeValuesSingleBlock(SortedNumericDocValues values, long numValues, int numBitsPerValue, long min, long gcd, Map<Long, Integer> encode) throws IOException { DirectWriter writer = DirectWriter.getInstance(data, numValues, numBitsPerValue); for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) { for (int i = 0, count = values.docValueCount(); i < count; ++i) { long v = values.nextValue(); if (encode == null) { writer.add((v - min) / gcd); } else { writer.add(encode.get(v)); } } } writer.finish(); }
Example 3
Source File: Lucene80DocValuesConsumer.java From lucene-solr with Apache License 2.0 | 5 votes |
private long writeValuesMultipleBlocks(SortedNumericDocValues values, long gcd) throws IOException { long[] offsets = new long[ArrayUtil.oversize(1, Long.BYTES)]; int offsetsIndex = 0; final long[] buffer = new long[NUMERIC_BLOCK_SIZE]; final ByteBuffersDataOutput encodeBuffer = ByteBuffersDataOutput.newResettableInstance(); int upTo = 0; for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) { for (int i = 0, count = values.docValueCount(); i < count; ++i) { buffer[upTo++] = values.nextValue(); if (upTo == NUMERIC_BLOCK_SIZE) { offsets = ArrayUtil.grow(offsets, offsetsIndex+1); offsets[offsetsIndex++] = data.getFilePointer(); writeBlock(buffer, NUMERIC_BLOCK_SIZE, gcd, encodeBuffer); upTo = 0; } } } if (upTo > 0) { offsets = ArrayUtil.grow(offsets, offsetsIndex+1); offsets[offsetsIndex++] = data.getFilePointer(); writeBlock(buffer, upTo, gcd, encodeBuffer); } // All blocks has been written. Flush the offset jump-table final long offsetsOrigo = data.getFilePointer(); for (int i = 0 ; i < offsetsIndex ; i++) { data.writeLong(offsets[i]); } data.writeLong(offsetsOrigo); return offsetsOrigo; }
Example 4
Source File: LatLonDocValuesPointInPolygonQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { return new ConstantScoreWeight(this, boost) { final Component2D tree = LatLonGeometry.create(polygons); final GeoEncodingUtils.PolygonPredicate polygonPredicate = GeoEncodingUtils.createComponentPredicate(tree); @Override public Scorer scorer(LeafReaderContext context) throws IOException { final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field); if (values == null) { return null; } final TwoPhaseIterator iterator = new TwoPhaseIterator(values) { @Override public boolean matches() throws IOException { for (int i = 0, count = values.docValueCount(); i < count; ++i) { final long value = values.nextValue(); final int lat = (int) (value >>> 32); final int lon = (int) (value & 0xFFFFFFFF); if (polygonPredicate.test(lat, lon)) { return true; } } return false; } @Override public float matchCost() { return 1000f; // TODO: what should it be? } }; return new ConstantScoreScorer(this, boost, scoreMode, iterator); } @Override public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, field); } }; }
Example 5
Source File: LatLonDocValuesDistanceQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { return new ConstantScoreWeight(this, boost) { private final GeoEncodingUtils.DistancePredicate distancePredicate = GeoEncodingUtils.createDistancePredicate(latitude, longitude, radiusMeters); @Override public Scorer scorer(LeafReaderContext context) throws IOException { final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field); if (values == null) { return null; } final TwoPhaseIterator iterator = new TwoPhaseIterator(values) { @Override public boolean matches() throws IOException { for (int i = 0, count = values.docValueCount(); i < count; ++i) { final long value = values.nextValue(); final int lat = (int) (value >>> 32); final int lon = (int) (value & 0xFFFFFFFF); if (distancePredicate.test(lat, lon)) { return true; } } return false; } @Override public float matchCost() { return 100f; // TODO: what should it be? } }; return new ConstantScoreScorer(this, boost, scoreMode, iterator); } @Override public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, field); } }; }
Example 6
Source File: XYDocValuesPointInGeometryQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { return new ConstantScoreWeight(this, boost) { final Component2D component2D = XYGeometry.create(geometries); @Override public Scorer scorer(LeafReaderContext context) throws IOException { final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field); if (values == null) { return null; } final TwoPhaseIterator iterator = new TwoPhaseIterator(values) { @Override public boolean matches() throws IOException { for (int i = 0, count = values.docValueCount(); i < count; ++i) { final long value = values.nextValue(); final double x = XYEncodingUtils.decode((int) (value >>> 32)); final double y = XYEncodingUtils.decode((int) (value & 0xFFFFFFFF)); if (component2D.contains(x, y)) { return true; } } return false; } @Override public float matchCost() { return 1000f; // TODO: what should it be? } }; return new ConstantScoreScorer(this, boost, scoreMode, iterator); } @Override public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, field); } }; }
Example 7
Source File: LatLonDocValuesBoxQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { return new ConstantScoreWeight(this, boost) { @Override public Scorer scorer(LeafReaderContext context) throws IOException { final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field); if (values == null) { return null; } final TwoPhaseIterator iterator = new TwoPhaseIterator(values) { @Override public boolean matches() throws IOException { for (int i = 0, count = values.docValueCount(); i < count; ++i) { final long value = values.nextValue(); final int lat = (int) (value >>> 32); if (lat < minLatitude || lat > maxLatitude) { // not within latitude range continue; } final int lon = (int) (value & 0xFFFFFFFF); if (crossesDateline) { if (lon > maxLongitude && lon < minLongitude) { // not within longitude range continue; } } else { if (lon < minLongitude || lon > maxLongitude) { // not within longitude range continue; } } return true; } return false; } @Override public float matchCost() { return 5; // 5 comparisons } }; return new ConstantScoreScorer(this, boost, scoreMode, iterator); } @Override public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, field); } }; }