/** * Retrieves an instance from the specified slice written decoding * {@code bitsPerValue} for each value */ public static LongValues getInstance(RandomAccessInput slice, int bitsPerValue) { switch (bitsPerValue) { case 1: return new DirectPackedReader1(slice); case 2: return new DirectPackedReader2(slice); case 4: return new DirectPackedReader4(slice); case 8: return new DirectPackedReader8(slice); case 12: return new DirectPackedReader12(slice); case 16: return new DirectPackedReader16(slice); case 20: return new DirectPackedReader20(slice); case 24: return new DirectPackedReader24(slice); case 28: return new DirectPackedReader28(slice); case 32: return new DirectPackedReader32(slice); case 40: return new DirectPackedReader40(slice); case 48: return new DirectPackedReader48(slice); case 56: return new DirectPackedReader56(slice); case 64: return new DirectPackedReader64(slice); default: throw new IllegalArgumentException("unsupported bitsPerValue: " + bitsPerValue); } }
/** accumulates per-segment multi-valued facet counts, mapping to global ordinal space on-the-fly */ static void accumMultiGeneric(int counts[], int startTermIndex, SortedSetDocValues 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) { si.setDocument(doc); // strange do-while to collect the missing count (first ord is NO_MORE_ORDS) int term = (int) si.nextOrd(); if (term < 0) { if (startTermIndex == -1) { counts[0]++; // missing count } continue; } do { if (map != null) { term = (int) ordMap.get(term); } int arrIdx = term-startTermIndex; if (arrIdx>=0 && arrIdx<counts.length) counts[arrIdx]++; } while ((term = (int) si.nextOrd()) >= 0); } }
@Override public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException { SortedSetEntry ss = sortedNumerics.get(field.number); NumericEntry numericEntry = numerics.get(field.number); final LongValues values = getNumeric(numericEntry); if (ss.format == SORTED_SINGLE_VALUED) { final Bits docsWithField = getMissingBits(numericEntry.missingOffset); return DocValues.singleton(values, docsWithField); } else if (ss.format == SORTED_WITH_ADDRESSES) { final IndexInput data = this.data.clone(); final MonotonicBlockPackedReader ordIndex = getOrdIndexInstance(data, field, ordIndexes.get(field.number)); return new SortedNumericDocValues() { long startOffset; long endOffset; @Override public void setDocument(int doc) { startOffset = ordIndex.get(doc); endOffset = ordIndex.get(doc+1L); } @Override public long valueAt(int index) { return values.get(startOffset + index); } @Override public int count() { return (int) (endOffset - startOffset); } }; } else { throw new AssertionError(); } }
@Override public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException { SortedSetEntry ss = sortedNumerics.get(field.number); NumericEntry numericEntry = numerics.get(field.number); final LongValues values = getNumeric(numericEntry); if (ss.format == SORTED_SINGLE_VALUED) { final Bits docsWithField = getMissingBits(numericEntry.missingOffset); return DocValues.singleton(values, docsWithField); } else if (ss.format == SORTED_WITH_ADDRESSES) { final MonotonicBlockPackedReader ordIndex = getOrdIndexInstance(field, ordIndexes.get(field.number)); return new SortedNumericDocValues() { long startOffset; long endOffset; @Override public void setDocument(int doc) { startOffset = ordIndex.get(doc); endOffset = ordIndex.get(doc+1L); } @Override public long valueAt(int index) { return values.get(startOffset + index); } @Override public int count() { return (int) (endOffset - startOffset); } }; } else { throw new AssertionError(); } }
/** 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 = si.getOrd(doc); if (map != null && term >= 0) { term = (int) ordmap.get(term); } int arrIdx = term-startTermIndex; if (arrIdx>=0 && arrIdx<counts.length) counts[arrIdx]++; } }
/** folds counts in segment ordinal space (segCounts) into global ordinal space (counts) */ static void migrateGlobal(int counts[], int segCounts[], int subIndex, OrdinalMap map) { final LongValues ordMap = map.getGlobalOrds(subIndex); // missing count counts[0] += segCounts[0]; // migrate actual ordinals for (int ord = 1; ord < segCounts.length; ord++) { int count = segCounts[ord]; if (count != 0) { counts[1+(int) ordMap.get(ord-1)] += count; } } }
public long accumulateObject(Object o, long shallowSize, java.util.Map<Field,Object> fieldValues, java.util.Collection<Object> queue) { if (o == LongValues.IDENTITY) { return 0L; } if (o instanceof OrdinalMap) { fieldValues = new HashMap<>(fieldValues); fieldValues.remove(ORDINAL_MAP_OWNER_FIELD); } return super.accumulateObject(o, shallowSize, fieldValues, queue); }
@Override public SortedDocValues getSorted(FieldInfo field) throws IOException { final int valueCount = (int) binaries.get(field.number).count; final BinaryDocValues binary = getBinary(field); NumericEntry entry = ords.get(field.number); final LongValues ordinals = getNumeric(entry); return new SortedDocValues() { @Override public int getOrd(int docID) { return (int) ordinals.get(docID); } @Override public BytesRef lookupOrd(int ord) { return binary.get(ord); } @Override public int getValueCount() { return valueCount; } @Override public int lookupTerm(BytesRef key) { if (binary instanceof CompressedBinaryDocValues) { return (int) ((CompressedBinaryDocValues)binary).lookupTerm(key); } else { return super.lookupTerm(key); } } @Override public TermsEnum termsEnum() { if (binary instanceof CompressedBinaryDocValues) { return ((CompressedBinaryDocValues)binary).getTermsEnum(); } else { return super.termsEnum(); } } }; }
/** * Given a segment number, return a {@link LongValues} instance that maps * segment ordinals to global ordinals. */ public LongValues getGlobalOrds(int segmentIndex) { return segmentToGlobalOrds[segmentMap.oldToNew(segmentIndex)]; }