Search in sources :

Example 1 with MutablePointValues

use of org.apache.lucene.codecs.MutablePointValues in project lucene-solr by apache.

the class PointValuesWriter method flush.

public void flush(SegmentWriteState state, Sorter.DocMap sortMap, PointsWriter writer) throws IOException {
    PointValues points = new MutablePointValues() {

        final int[] ords = new int[numPoints];

        {
            for (int i = 0; i < numPoints; ++i) {
                ords[i] = i;
            }
        }

        @Override
        public void intersect(IntersectVisitor visitor) throws IOException {
            final BytesRef scratch = new BytesRef();
            final byte[] packedValue = new byte[packedBytesLength];
            for (int i = 0; i < numPoints; i++) {
                getValue(i, scratch);
                assert scratch.length == packedValue.length;
                System.arraycopy(scratch.bytes, scratch.offset, packedValue, 0, packedBytesLength);
                visitor.visit(getDocID(i), packedValue);
            }
        }

        @Override
        public long estimatePointCount(IntersectVisitor visitor) {
            throw new UnsupportedOperationException();
        }

        @Override
        public byte[] getMinPackedValue() {
            throw new UnsupportedOperationException();
        }

        @Override
        public byte[] getMaxPackedValue() {
            throw new UnsupportedOperationException();
        }

        @Override
        public int getNumDimensions() {
            throw new UnsupportedOperationException();
        }

        @Override
        public int getBytesPerDimension() {
            throw new UnsupportedOperationException();
        }

        @Override
        public long size() {
            return numPoints;
        }

        @Override
        public int getDocCount() {
            return numDocs;
        }

        @Override
        public void swap(int i, int j) {
            int tmp = ords[i];
            ords[i] = ords[j];
            ords[j] = tmp;
        }

        @Override
        public int getDocID(int i) {
            return docIDs[ords[i]];
        }

        @Override
        public void getValue(int i, BytesRef packedValue) {
            final long offset = (long) packedBytesLength * ords[i];
            packedValue.length = packedBytesLength;
            bytes.setRawBytesRef(packedValue, offset);
        }

        @Override
        public byte getByteAt(int i, int k) {
            final long offset = (long) packedBytesLength * ords[i] + k;
            return bytes.readByte(offset);
        }
    };
    final PointValues values;
    if (sortMap == null) {
        values = points;
    } else {
        values = new MutableSortingPointValues((MutablePointValues) points, sortMap);
    }
    PointsReader reader = new PointsReader() {

        @Override
        public PointValues getValues(String fieldName) {
            if (fieldName.equals(fieldInfo.name) == false) {
                throw new IllegalArgumentException("fieldName must be the same");
            }
            return values;
        }

        @Override
        public void checkIntegrity() {
            throw new UnsupportedOperationException();
        }

        @Override
        public long ramBytesUsed() {
            return 0L;
        }

        @Override
        public void close() {
        }
    };
    writer.writeField(fieldInfo, reader);
}
Also used : MutablePointValues(org.apache.lucene.codecs.MutablePointValues) PointsReader(org.apache.lucene.codecs.PointsReader) BytesRef(org.apache.lucene.util.BytesRef) MutablePointValues(org.apache.lucene.codecs.MutablePointValues)

Example 2 with MutablePointValues

use of org.apache.lucene.codecs.MutablePointValues in project lucene-solr by apache.

the class Lucene60PointsWriter method writeField.

@Override
public void writeField(FieldInfo fieldInfo, PointsReader reader) throws IOException {
    PointValues values = reader.getValues(fieldInfo.name);
    boolean singleValuePerDoc = values.size() == values.getDocCount();
    try (BKDWriter writer = new BKDWriter(writeState.segmentInfo.maxDoc(), writeState.directory, writeState.segmentInfo.name, fieldInfo.getPointDimensionCount(), fieldInfo.getPointNumBytes(), maxPointsInLeafNode, maxMBSortInHeap, values.size(), singleValuePerDoc)) {
        if (values instanceof MutablePointValues) {
            final long fp = writer.writeField(dataOut, fieldInfo.name, (MutablePointValues) values);
            if (fp != -1) {
                indexFPs.put(fieldInfo.name, fp);
            }
            return;
        }
        values.intersect(new IntersectVisitor() {

            @Override
            public void visit(int docID) {
                throw new IllegalStateException();
            }

            public void visit(int docID, byte[] packedValue) throws IOException {
                writer.add(packedValue, docID);
            }

            @Override
            public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
                return Relation.CELL_CROSSES_QUERY;
            }
        });
        // We could have 0 points on merge since all docs with dimensional fields may be deleted:
        if (writer.getPointCount() > 0) {
            indexFPs.put(fieldInfo.name, writer.finish(dataOut));
        }
    }
}
Also used : MutablePointValues(org.apache.lucene.codecs.MutablePointValues) PointValues(org.apache.lucene.index.PointValues) Relation(org.apache.lucene.index.PointValues.Relation) IntersectVisitor(org.apache.lucene.index.PointValues.IntersectVisitor) IOException(java.io.IOException) BKDWriter(org.apache.lucene.util.bkd.BKDWriter) MutablePointValues(org.apache.lucene.codecs.MutablePointValues)

Aggregations

MutablePointValues (org.apache.lucene.codecs.MutablePointValues)2 IOException (java.io.IOException)1 PointsReader (org.apache.lucene.codecs.PointsReader)1 PointValues (org.apache.lucene.index.PointValues)1 IntersectVisitor (org.apache.lucene.index.PointValues.IntersectVisitor)1 Relation (org.apache.lucene.index.PointValues.Relation)1 BytesRef (org.apache.lucene.util.BytesRef)1 BKDWriter (org.apache.lucene.util.bkd.BKDWriter)1