Search in sources :

Example 21 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class DocValuesFacets method accumSingleGeneric.

/** accumulates per-segment single-valued facet counts, mapping to global ordinal space on-the-fly */
static void accumSingleGeneric(int[] counts, int startTermIndex, SortedDocValues si, DocIdSetIterator disi, int subIndex, OrdinalMap map) throws IOException {
    final LongValues ordmap = map == null ? null : map.getGlobalOrds(subIndex);
    int doc;
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        int term;
        if (si.advanceExact(doc)) {
            term = si.ordValue();
        } else {
            term = -1;
        }
        if (map != null && term >= 0) {
            term = (int) ordmap.get(term);
        }
        int arrIdx = term - startTermIndex;
        if (arrIdx >= 0 && arrIdx < counts.length)
            counts[arrIdx]++;
    }
}
Also used : LongValues(org.apache.lucene.util.LongValues)

Example 22 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class DocValuesStats method accumMulti.

/** accumulates per-segment multi-valued stats */
static int accumMulti(int[] counts, int docBase, FieldFacetStats[] facetStats, SortedSetDocValues si, DocIdSetIterator disi, int subIndex, OrdinalMap map) throws IOException {
    final LongValues ordMap = map == null ? null : map.getGlobalOrds(subIndex);
    int missingDocCount = 0;
    int doc;
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        if (doc > si.docID()) {
            si.advance(doc);
        }
        if (doc == si.docID()) {
            long ord;
            while ((ord = si.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
                int term = (int) ord;
                if (map != null) {
                    term = (int) ordMap.get(term);
                }
                counts[term]++;
                for (FieldFacetStats f : facetStats) {
                    f.facetTermNum(docBase + doc, term);
                }
            }
        } else {
            for (FieldFacetStats f : facetStats) {
                f.facetMissingNum(docBase + doc);
            }
            missingDocCount++;
        }
    }
    return missingDocCount;
}
Also used : FieldFacetStats(org.apache.solr.handler.component.FieldFacetStats) LongValues(org.apache.lucene.util.LongValues)

Example 23 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene70DocValuesProducer method getSortedNumeric.

@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
    SortedNumericEntry entry = sortedNumerics.get(field.name);
    if (entry.numValues == entry.numDocsWithField) {
        return DocValues.singleton(getNumeric(entry));
    }
    final RandomAccessInput addressesInput = data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
    final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
    final LongValues values = getNumericValues(entry);
    if (entry.docsWithFieldOffset == -1) {
        // dense
        return new SortedNumericDocValues() {

            int doc = -1;

            long start, end;

            int count;

            @Override
            public int nextDoc() throws IOException {
                return advance(doc + 1);
            }

            @Override
            public int docID() {
                return doc;
            }

            @Override
            public long cost() {
                return maxDoc;
            }

            @Override
            public int advance(int target) throws IOException {
                if (target >= maxDoc) {
                    return doc = NO_MORE_DOCS;
                }
                start = addresses.get(target);
                end = addresses.get(target + 1L);
                count = (int) (end - start);
                return doc = target;
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                start = addresses.get(target);
                end = addresses.get(target + 1L);
                count = (int) (end - start);
                doc = target;
                return true;
            }

            @Override
            public long nextValue() throws IOException {
                return values.get(start++);
            }

            @Override
            public int docValueCount() {
                return count;
            }
        };
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        return new SortedNumericDocValues() {

            boolean set;

            long start, end;

            int count;

            @Override
            public int nextDoc() throws IOException {
                set = false;
                return disi.nextDoc();
            }

            @Override
            public int docID() {
                return disi.docID();
            }

            @Override
            public long cost() {
                return disi.cost();
            }

            @Override
            public int advance(int target) throws IOException {
                set = false;
                return disi.advance(target);
            }

            @Override
            public boolean advanceExact(int target) throws IOException {
                set = false;
                return disi.advanceExact(target);
            }

            @Override
            public long nextValue() throws IOException {
                set();
                return values.get(start++);
            }

            @Override
            public int docValueCount() {
                set();
                return count;
            }

            private void set() {
                if (set == false) {
                    final int index = disi.index();
                    start = addresses.get(index);
                    end = addresses.get(index + 1L);
                    count = (int) (end - start);
                    set = true;
                }
            }
        };
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) LongValues(org.apache.lucene.util.LongValues)

Example 24 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class Lucene70DocValuesProducer method getBinary.

@Override
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
    BinaryEntry entry = binaries.get(field.name);
    if (entry.docsWithFieldOffset == -2) {
        return DocValues.emptyBinary();
    }
    final IndexInput bytesSlice = data.slice("fixed-binary", entry.dataOffset, entry.dataLength);
    if (entry.docsWithFieldOffset == -1) {
        // dense
        if (entry.minLength == entry.maxLength) {
            // fixed length
            final int length = entry.maxLength;
            return new DenseBinaryDocValues(maxDoc) {

                final BytesRef bytes = new BytesRef(new byte[length], 0, length);

                @Override
                public BytesRef binaryValue() throws IOException {
                    bytesSlice.seek((long) doc * length);
                    bytesSlice.readBytes(bytes.bytes, 0, length);
                    return bytes;
                }
            };
        } else {
            // variable length
            final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
            final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
            return new DenseBinaryDocValues(maxDoc) {

                final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);

                @Override
                public BytesRef binaryValue() throws IOException {
                    long startOffset = addresses.get(doc);
                    bytes.length = (int) (addresses.get(doc + 1L) - startOffset);
                    bytesSlice.seek(startOffset);
                    bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
                    return bytes;
                }
            };
        }
    } else {
        // sparse
        final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
        if (entry.minLength == entry.maxLength) {
            // fixed length
            final int length = entry.maxLength;
            return new SparseBinaryDocValues(disi) {

                final BytesRef bytes = new BytesRef(new byte[length], 0, length);

                @Override
                public BytesRef binaryValue() throws IOException {
                    bytesSlice.seek((long) disi.index() * length);
                    bytesSlice.readBytes(bytes.bytes, 0, length);
                    return bytes;
                }
            };
        } else {
            // variable length
            final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
            final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
            return new SparseBinaryDocValues(disi) {

                final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);

                @Override
                public BytesRef binaryValue() throws IOException {
                    final int index = disi.index();
                    long startOffset = addresses.get(index);
                    bytes.length = (int) (addresses.get(index + 1L) - startOffset);
                    bytesSlice.seek(startOffset);
                    bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
                    return bytes;
                }
            };
        }
    }
}
Also used : RandomAccessInput(org.apache.lucene.store.RandomAccessInput) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) BytesRef(org.apache.lucene.util.BytesRef)

Example 25 with LongValues

use of org.apache.lucene.util.LongValues in project lucene-solr by apache.

the class TestPackedInts method testPagedMutable.

public void testPagedMutable() {
    final int bitsPerValue = TestUtil.nextInt(random(), 1, 64);
    final long max = PackedInts.maxValue(bitsPerValue);
    int pageSize = 1 << (TestUtil.nextInt(random(), 6, 30));
    // supports 0 values?
    PagedMutable writer = new PagedMutable(0, pageSize, bitsPerValue, random().nextFloat() / 2);
    assertEquals(0, writer.size());
    // compare against AppendingDeltaPackedLongBuffer
    PackedLongValues.Builder buf = PackedLongValues.deltaPackedBuilder(random().nextFloat());
    int size = random().nextInt(1000000);
    for (int i = 0; i < size; ++i) {
        buf.add(bitsPerValue == 64 ? random().nextLong() : TestUtil.nextLong(random(), 0, max));
    }
    writer = new PagedMutable(size, pageSize, bitsPerValue, random().nextFloat());
    assertEquals(size, writer.size());
    final LongValues values = buf.build();
    for (int i = size - 1; i >= 0; --i) {
        writer.set(i, values.get(i));
    }
    for (int i = 0; i < size; ++i) {
        assertEquals(values.get(i), writer.get(i));
    }
    // test ramBytesUsed
    assertEquals(RamUsageTester.sizeOf(writer) - RamUsageTester.sizeOf(writer.format), writer.ramBytesUsed());
    // test copy
    PagedMutable copy = writer.resize(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
    for (long i = 0; i < copy.size(); ++i) {
        if (i < writer.size()) {
            assertEquals(writer.get(i), copy.get(i));
        } else {
            assertEquals(0, copy.get(i));
        }
    }
    // test grow
    PagedMutable grow = writer.grow(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
    for (long i = 0; i < grow.size(); ++i) {
        if (i < writer.size()) {
            assertEquals(writer.get(i), grow.get(i));
        } else {
            assertEquals(0, grow.get(i));
        }
    }
}
Also used : LongValues(org.apache.lucene.util.LongValues)

Aggregations

LongValues (org.apache.lucene.util.LongValues)31 IOException (java.io.IOException)8 RandomAccessInput (org.apache.lucene.store.RandomAccessInput)8 IndexInput (org.apache.lucene.store.IndexInput)7 BytesRef (org.apache.lucene.util.BytesRef)6 IndexOutput (org.apache.lucene.store.IndexOutput)5 Directory (org.apache.lucene.store.Directory)4 ArrayList (java.util.ArrayList)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 NumericDocValues (org.apache.lucene.index.NumericDocValues)3 SortedDocValues (org.apache.lucene.index.SortedDocValues)3 Bits (org.apache.lucene.util.Bits)3 MultiDocValues (org.apache.lucene.index.MultiDocValues)2 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)2 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 DirectWriter (org.apache.lucene.util.packed.DirectWriter)2 FieldFacetStats (org.apache.solr.handler.component.FieldFacetStats)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1