@Override public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, final Iterable<Number> docToOrdCount, final Iterable<Number> ords) throws IOException { meta.writeVInt(field.number); meta.writeByte(Lucene410DocValuesFormat.SORTED_SET); if (isSingleValued(docToOrdCount)) { meta.writeVInt(SORTED_SINGLE_VALUED); // The field is single-valued, we can encode it as SORTED addSortedField(field, values, singletonView(docToOrdCount, ords, -1L)); } else { meta.writeVInt(SORTED_WITH_ADDRESSES); // write the ord -> byte[] as a binary field addTermsDict(field, values); // write the stream of ords as a numeric field // NOTE: we could return an iterator that delta-encodes these within a doc addNumericField(field, ords, false); // write the doc -> ord count as a absolute index to the stream addAddresses(field, docToOrdCount); } }
@Override FieldStats.Long stats(IndexReader reader, String fieldName, boolean isSearchable, boolean isAggregatable) throws IOException { FieldInfo fi = org.apache.lucene.index.MultiFields.getMergedFieldInfos(reader).fieldInfo(fieldName); if (fi == null) { return null; } long size = PointValues.size(reader, fieldName); if (size == 0) { return new FieldStats.Long(reader.maxDoc(), 0, -1, -1, isSearchable, isAggregatable); } int docCount = PointValues.getDocCount(reader, fieldName); byte[] min = PointValues.getMinPackedValue(reader, fieldName); byte[] max = PointValues.getMaxPackedValue(reader, fieldName); return new FieldStats.Long(reader.maxDoc(),docCount, -1L, size, isSearchable, isAggregatable, IntPoint.decodeDimension(min, 0), IntPoint.decodeDimension(max, 0)); }
@Override FieldStats.Long stats(IndexReader reader, String fieldName, boolean isSearchable, boolean isAggregatable) throws IOException { FieldInfo fi = org.apache.lucene.index.MultiFields.getMergedFieldInfos(reader).fieldInfo(fieldName); if (fi == null) { return null; } long size = PointValues.size(reader, fieldName); if (size == 0) { return new FieldStats.Long(reader.maxDoc(), 0, -1, -1, isSearchable, isAggregatable); } int docCount = PointValues.getDocCount(reader, fieldName); byte[] min = PointValues.getMinPackedValue(reader, fieldName); byte[] max = PointValues.getMaxPackedValue(reader, fieldName); return new FieldStats.Long(reader.maxDoc(),docCount, -1L, size, isSearchable, isAggregatable, LongPoint.decodeDimension(min, 0), LongPoint.decodeDimension(max, 0)); }
@Override public Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField) throws IOException { final NumericDocValues valuesIn = reader.getNumericDocValues(field); if (valuesIn != null) { // Not cached here by FieldCacheImpl (cached instead // per-thread by SegmentReader): return new Longs() { @Override public long get(int docID) { return valuesIn.get(docID); } }; } else { final FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info == null) { return Longs.EMPTY; } else if (info.hasDocValues()) { throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType()); } else if (!info.isIndexed()) { return Longs.EMPTY; } return (Longs) caches.get(Long.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField); } }
void seek(TermInfo ti, Term term) throws IOException { count = 0; FieldInfo fi = fieldInfos.fieldInfo(term.field()); this.indexOptions = (fi != null) ? fi.getIndexOptions() : IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; currentFieldStoresPayloads = (fi != null) ? fi.hasPayloads() : false; if (ti == null) { df = 0; } else { df = ti.docFreq; doc = 0; freqBasePointer = ti.freqPointer; proxBasePointer = ti.proxPointer; skipPointer = freqBasePointer + ti.skipOffset; freqStream.seek(freqBasePointer); haveSkipped = false; } }
private void addAddresses(FieldInfo field, Iterable<Number> values) throws IOException { meta.writeVInt(field.number); meta.writeByte(Lucene410DocValuesFormat.NUMERIC); meta.writeVInt(MONOTONIC_COMPRESSED); meta.writeLong(-1L); meta.writeLong(data.getFilePointer()); meta.writeVLong(maxDoc); meta.writeVInt(PackedInts.VERSION_CURRENT); meta.writeVInt(BLOCK_SIZE); final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(data, BLOCK_SIZE); long addr = 0; writer.add(addr); for (Number v : values) { addr += v.longValue(); writer.add(addr); } writer.finish(); meta.writeLong(data.getFilePointer()); }
@Override public Ints getInts(AtomicReader reader, String field, IntParser parser, boolean setDocsWithField) throws IOException { final NumericDocValues valuesIn = reader.getNumericDocValues(field); if (valuesIn != null) { // Not cached here by FieldCacheImpl (cached instead // per-thread by SegmentReader): return new Ints() { @Override public int get(int docID) { return (int) valuesIn.get(docID); } }; } else { final FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info == null) { return Ints.EMPTY; } else if (info.hasDocValues()) { throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType()); } else if (!info.isIndexed()) { return Ints.EMPTY; } return (Ints) caches.get(Integer.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField); } }
@Override public void encodeTerm(long[] longs, DataOutput out, FieldInfo fieldInfo, BlockTermState _state, boolean absolute) throws IOException { IntBlockTermState state = (IntBlockTermState)_state; if (absolute) { lastState = emptyState; } longs[0] = state.docStartFP - lastState.docStartFP; if (fieldHasPositions) { longs[1] = state.posStartFP - lastState.posStartFP; if (fieldHasPayloads || fieldHasOffsets) { longs[2] = state.payStartFP - lastState.payStartFP; } } if (state.singletonDocID != -1) { out.writeVInt(state.singletonDocID); } if (fieldHasPositions) { if (state.lastPosBlockOffset != -1) { out.writeVLong(state.lastPosBlockOffset); } } if (state.skipOffset != -1) { out.writeVLong(state.skipOffset); } lastState = state; }
private NumericDocValues loadByteField(FieldInfo field, IndexInput input) throws IOException { CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME, Lucene40DocValuesFormat.INTS_VERSION_START, Lucene40DocValuesFormat.INTS_VERSION_CURRENT); int valueSize = input.readInt(); if (valueSize != 1) { throw new CorruptIndexException("invalid valueSize: " + valueSize); } int maxDoc = state.segmentInfo.getDocCount(); final byte values[] = new byte[maxDoc]; input.readBytes(values, 0, values.length); ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values)); return new NumericDocValues() { @Override public long get(int docID) { return values[docID]; } }; }
private NumericDocValues loadFloatField(FieldInfo field, IndexInput input) throws IOException { CodecUtil.checkHeader(input, Lucene40DocValuesFormat.FLOATS_CODEC_NAME, Lucene40DocValuesFormat.FLOATS_VERSION_START, Lucene40DocValuesFormat.FLOATS_VERSION_CURRENT); int valueSize = input.readInt(); if (valueSize != 4) { throw new CorruptIndexException("invalid valueSize: " + valueSize); } int maxDoc = state.segmentInfo.getDocCount(); final int values[] = new int[maxDoc]; for (int i = 0; i < values.length; i++) { values[i] = input.readInt(); } ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values)); return new NumericDocValues() { @Override public long get(int docID) { return values[docID]; } }; }
@Override public synchronized BinaryDocValues getBinary(FieldInfo field) throws IOException { BinaryDocValues instance = binaryInstances.get(field.number); if (instance == null) { switch(LegacyDocValuesType.valueOf(field.getAttribute(legacyKey))) { case BYTES_FIXED_STRAIGHT: instance = loadBytesFixedStraight(field); break; case BYTES_VAR_STRAIGHT: instance = loadBytesVarStraight(field); break; case BYTES_FIXED_DEREF: instance = loadBytesFixedDeref(field); break; case BYTES_VAR_DEREF: instance = loadBytesVarDeref(field); break; default: throw new AssertionError(); } binaryInstances.put(field.number, instance); } return instance; }
@Override public Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField) throws IOException { final NumericDocValues valuesIn = reader.getNumericDocValues(field); if (valuesIn != null) { // Not cached here by FieldCacheImpl (cached instead // per-thread by SegmentReader): return new Doubles() { @Override public double get(int docID) { return Double.longBitsToDouble(valuesIn.get(docID)); } }; } else { final FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info == null) { return Doubles.EMPTY; } else if (info.hasDocValues()) { throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType()); } else if (!info.isIndexed()) { return Doubles.EMPTY; } return (Doubles) caches.get(Double.TYPE).get(reader, new CacheKey(field, parser), setDocsWithField); } }
@Override public Bits getDocsWithField(FieldInfo field) throws IOException { switch(field.getDocValuesType()) { case SORTED_SET: return DocValues.docsWithValue(getSortedSet(field), maxDoc); case SORTED_NUMERIC: return DocValues.docsWithValue(getSortedNumeric(field), maxDoc); case SORTED: return DocValues.docsWithValue(getSorted(field), maxDoc); case BINARY: BinaryEntry be = binaries.get(field.number); return getMissingBits(be.missingOffset); case NUMERIC: NumericEntry ne = numerics.get(field.number); return getMissingBits(ne.missingOffset); default: throw new AssertionError(); } }
/** returns an address instance for prefix-compressed binary values. * @lucene.internal */ protected MonotonicBlockPackedReader getIntervalInstance(IndexInput data, FieldInfo field, BinaryEntry bytes) throws IOException { final MonotonicBlockPackedReader addresses; final long interval = bytes.addressInterval; synchronized (addressInstances) { MonotonicBlockPackedReader addrInstance = addressInstances.get(field.number); if (addrInstance == null) { data.seek(bytes.addressesOffset); final long size; if (bytes.count % interval == 0) { size = bytes.count / interval; } else { size = 1L + bytes.count / interval; } addrInstance = MonotonicBlockPackedReader.of(data, bytes.packedIntsVersion, bytes.blockSize, size, false); addressInstances.put(field.number, addrInstance); ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT); } addresses = addrInstance; } return addresses; }
@Override public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, final Iterable<Number> docToOrdCount, final Iterable<Number> ords) throws IOException { checkCanWrite(field); meta.writeVInt(field.number); meta.writeByte(Lucene49DocValuesFormat.SORTED_SET); if (isSingleValued(docToOrdCount)) { meta.writeVInt(SORTED_SINGLE_VALUED); // The field is single-valued, we can encode it as SORTED addSortedField(field, values, singletonView(docToOrdCount, ords, -1L)); } else { meta.writeVInt(SORTED_WITH_ADDRESSES); // write the ord -> byte[] as a binary field addTermsDict(field, values); // write the stream of ords as a numeric field // NOTE: we could return an iterator that delta-encodes these within a doc addNumericField(field, ords, false); // write the doc -> ord count as a absolute index to the stream addAddresses(field, docToOrdCount); } }
@Override public void addSortedNumericField(FieldInfo field, final Iterable<Number> docToValueCount, final Iterable<Number> values) throws IOException { checkCanWrite(field); meta.writeVInt(field.number); meta.writeByte(Lucene49DocValuesFormat.SORTED_NUMERIC); if (isSingleValued(docToValueCount)) { meta.writeVInt(SORTED_SINGLE_VALUED); // The field is single-valued, we can encode it as NUMERIC addNumericField(field, singletonView(docToValueCount, values, null)); } else { meta.writeVInt(SORTED_WITH_ADDRESSES); // write the stream of values as a numeric field addNumericField(field, values, true); // write the doc -> ord count as a absolute index to the stream addAddresses(field, docToValueCount); } }
@Override public Bits getDocsWithField(FieldInfo field) throws IOException { if (field.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET) { return DocValues.docsWithValue(getSortedSet(field), maxDoc); } else { return new Bits.MatchAllBits(maxDoc); } }
@Override public AtomicGeoPointFieldData load(LeafReaderContext context) { try { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(fieldName); if (info != null) { checkCompatible(info); } return new LatLonPointDVAtomicFieldData(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } }
/** returns an address instance for sortedset ordinal lists */ private synchronized MonotonicBlockPackedReader getOrdIndexInstance(FieldInfo field, NumericEntry entry) throws IOException { MonotonicBlockPackedReader instance = ordIndexInstances.get(field.number); if (instance == null) { data.seek(entry.offset); instance = MonotonicBlockPackedReader.of(data, entry.packedIntsVersion, entry.blockSize, entry.count+1, false); ordIndexInstances.put(field.number, instance); ramBytesUsed.addAndGet(instance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT); } return instance; }
/** returns an address instance for variable-length binary values. */ private MonotonicBlockPackedReader getAddressInstance(IndexInput data, FieldInfo field, BinaryEntry bytes) throws IOException { final MonotonicBlockPackedReader addresses; synchronized (addressInstances) { MonotonicBlockPackedReader addrInstance = addressInstances.get(field.number); if (addrInstance == null) { data.seek(bytes.addressesOffset); addrInstance = MonotonicBlockPackedReader.of(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count+1, false); addressInstances.put(field.number, addrInstance); ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT); } addresses = addrInstance; } return addresses; }
private BinaryDocValues getCompressedBinary(FieldInfo field, final BinaryEntry bytes) throws IOException { final MonotonicBlockPackedReader addresses = getIntervalInstance(field, bytes); final ReverseTermsIndex index = getReverseIndexInstance(field, bytes); assert addresses.size() > 0; // we don't have to handle empty case IndexInput slice = data.slice("terms", bytes.offset, bytes.addressesOffset - bytes.offset); return new CompressedBinaryDocValues(bytes, addresses, index, slice); }
@Override public BinaryDocValues getBinary(FieldInfo field) throws IOException { BinaryEntry bytes = binaries.get(field.number); switch(bytes.format) { case BINARY_FIXED_UNCOMPRESSED: return getFixedBinary(field, bytes); case BINARY_VARIABLE_UNCOMPRESSED: return getVariableBinary(field, bytes); case BINARY_PREFIX_COMPRESSED: return getCompressedBinary(field, bytes); default: throw new AssertionError(); } }
/** returns an address instance for variable-length binary values. */ private synchronized MonotonicBlockPackedReader getAddressInstance(FieldInfo field, BinaryEntry bytes) throws IOException { MonotonicBlockPackedReader addresses = addressInstances.get(field.number); if (addresses == null) { data.seek(bytes.addressesOffset); addresses = MonotonicBlockPackedReader.of(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count+1, false); addressInstances.put(field.number, addresses); ramBytesUsed.addAndGet(addresses.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT); } return addresses; }
@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 NumericDocValues getNumeric(FieldInfo field) throws IOException { if (VersionFieldMapper.NAME.equals(field.name)) { // uninvert into a packed ints and expose as docvalues final Terms terms = reader.terms(UidFieldMapper.NAME); final TermsEnum uids = terms.iterator(); final GrowableWriter versions = new GrowableWriter(2, reader.maxDoc(), PackedInts.COMPACT); PostingsEnum dpe = null; for (BytesRef uid = uids.next(); uid != null; uid = uids.next()) { dpe = uids.postings(dpe, PostingsEnum.PAYLOADS); assert terms.hasPayloads() : "field has payloads"; final Bits liveDocs = reader.getLiveDocs(); for (int doc = dpe.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = dpe.nextDoc()) { if (liveDocs != null && liveDocs.get(doc) == false) { continue; } dpe.nextPosition(); final BytesRef payload = dpe.getPayload(); if (payload != null && payload.length == 8) { final long version = Numbers.bytesToLong(payload); versions.set(doc, version); break; } } } return versions; } else { return in.getNumeric(field); } }
@Override public Status needsField(FieldInfo fieldInfo) throws IOException { if (UidFieldMapper.NAME.equals(fieldInfo.name)) { return Status.YES; } return uid != null ? Status.STOP : Status.NO; }
@Override public Status needsField(FieldInfo fieldInfo) throws IOException { if (requiredFields.remove(fieldInfo.name)) { return Status.YES; } // All these fields are single-valued so we can stop when the set is // empty return requiredFields.isEmpty() ? Status.STOP : Status.NO; }
@Override public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { if (SourceFieldMapper.NAME.equals(fieldInfo.name)) { source = new BytesArray(value); } else { addValue(fieldInfo.name, new BytesRef(value)); } }
@Override public void stringField(FieldInfo fieldInfo, byte[] bytes) throws IOException { final String value = new String(bytes, StandardCharsets.UTF_8); if (UidFieldMapper.NAME.equals(fieldInfo.name)) { uid = Uid.createUid(value); } else { addValue(fieldInfo.name, value); } }
/** * Here, we verify that the order that we add fields to a document counts, and not the lexi order * of the field. This means that heavily accessed fields that use field selector should be added * first (with load and break). */ public void testOrdering() throws Exception { Directory dir = new RAMDirectory(); IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER)); Document document = new Document(); document.add(new TextField("_id", "1", Field.Store.YES)); document.add(new TextField("#id", "1", Field.Store.YES)); indexWriter.addDocument(document); IndexReader reader = DirectoryReader.open(indexWriter); IndexSearcher searcher = new IndexSearcher(reader); TopDocs topDocs = searcher.search(new TermQuery(new Term("_id", "1")), 1); final ArrayList<String> fieldsOrder = new ArrayList<>(); searcher.doc(topDocs.scoreDocs[0].doc, new StoredFieldVisitor() { @Override public Status needsField(FieldInfo fieldInfo) throws IOException { fieldsOrder.add(fieldInfo.name); return Status.YES; } }); assertThat(fieldsOrder.size(), equalTo(2)); assertThat(fieldsOrder.get(0), equalTo("_id")); assertThat(fieldsOrder.get(1), equalTo("#id")); indexWriter.close(); }
private void readField(StoredFieldVisitor visitor, FieldInfo info, int bits) throws IOException { final int numeric = bits & FIELD_IS_NUMERIC_MASK; if (numeric != 0) { switch(numeric) { case FIELD_IS_NUMERIC_INT: visitor.intField(info, fieldsStream.readInt()); return; case FIELD_IS_NUMERIC_LONG: visitor.longField(info, fieldsStream.readLong()); return; case FIELD_IS_NUMERIC_FLOAT: visitor.floatField(info, Float.intBitsToFloat(fieldsStream.readInt())); return; case FIELD_IS_NUMERIC_DOUBLE: visitor.doubleField(info, Double.longBitsToDouble(fieldsStream.readLong())); return; default: throw new CorruptIndexException("Invalid numeric type: " + Integer.toHexString(numeric)); } } else { final int length = fieldsStream.readVInt(); byte bytes[] = new byte[length]; fieldsStream.readBytes(bytes, 0, length); if ((bits & FIELD_IS_BINARY) != 0) { visitor.binaryField(info, bytes); } else { visitor.stringField(info, new String(bytes, 0, bytes.length, StandardCharsets.UTF_8)); } } }
private void addReverseTermIndex(FieldInfo field, final Iterable<BytesRef> values, int maxLength) throws IOException { long count = 0; BytesRefBuilder priorTerm = new BytesRefBuilder(); priorTerm.grow(maxLength); BytesRef indexTerm = new BytesRef(); long startFP = data.getFilePointer(); PagedBytes pagedBytes = new PagedBytes(15); MonotonicBlockPackedWriter addresses = new MonotonicBlockPackedWriter(data, BLOCK_SIZE); for (BytesRef b : values) { int termPosition = (int) (count & REVERSE_INTERVAL_MASK); if (termPosition == 0) { int len = StringHelper.sortKeyLength(priorTerm.get(), b); indexTerm.bytes = b.bytes; indexTerm.offset = b.offset; indexTerm.length = len; addresses.add(pagedBytes.copyUsingLengthPrefix(indexTerm)); } else if (termPosition == REVERSE_INTERVAL_MASK) { priorTerm.copyBytes(b); } count++; } addresses.finish(); long numBytes = pagedBytes.getPointer(); pagedBytes.freeze(true); PagedBytesDataInput in = pagedBytes.getDataInput(); meta.writeLong(startFP); data.writeVLong(numBytes); data.copyBytes(in, numBytes); }
public SegmentDocsAndPositionsEnum reset(FieldInfo fieldInfo, StandardTermState termState, Bits liveDocs) throws IOException { assert fieldInfo.getIndexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; assert !fieldInfo.hasPayloads(); this.liveDocs = liveDocs; // TODO: for full enum case (eg segment merging) this // seek is unnecessary; maybe we can avoid in such // cases freqIn.seek(termState.freqOffset); lazyProxPointer = termState.proxOffset; limit = termState.docFreq; assert limit > 0; ord = 0; doc = -1; accum = 0; position = 0; skipped = false; posPendingCount = 0; freqOffset = termState.freqOffset; proxOffset = termState.proxOffset; skipOffset = termState.skipOffset; // if (DEBUG) System.out.println("StandardR.D&PE reset seg=" + segment + " limit=" + limit + " freqFP=" + freqOffset + " proxFP=" + proxOffset); return this; }
public SegmentFullPositionsEnum reset(FieldInfo fieldInfo, StandardTermState termState, Bits liveDocs) throws IOException { storeOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; storePayloads = fieldInfo.hasPayloads(); assert fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; assert storePayloads || storeOffsets; if (payload == null) { payload = new BytesRefBuilder(); } this.liveDocs = liveDocs; // TODO: for full enum case (eg segment merging) this // seek is unnecessary; maybe we can avoid in such // cases freqIn.seek(termState.freqOffset); lazyProxPointer = termState.proxOffset; limit = termState.docFreq; ord = 0; doc = -1; accum = 0; position = 0; startOffset = 0; skipped = false; posPendingCount = 0; payloadPending = false; freqOffset = termState.freqOffset; proxOffset = termState.proxOffset; skipOffset = termState.skipOffset; //System.out.println("StandardR.D&PE reset seg=" + segment + " limit=" + limit + " freqFP=" + freqOffset + " proxFP=" + proxOffset + " this=" + this); return this; }
/** returns an address instance for sortedset ordinal lists */ private MonotonicBlockPackedReader getOrdIndexInstance(IndexInput data, FieldInfo field, NumericEntry entry) throws IOException { final MonotonicBlockPackedReader ordIndex; synchronized (ordIndexInstances) { MonotonicBlockPackedReader ordIndexInstance = ordIndexInstances.get(field.number); if (ordIndexInstance == null) { data.seek(entry.offset); ordIndexInstance = MonotonicBlockPackedReader.of(data, entry.packedIntsVersion, entry.blockSize, entry.count+1, false); ordIndexInstances.put(field.number, ordIndexInstance); ramBytesUsed.addAndGet(ordIndexInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT); } ordIndex = ordIndexInstance; } return ordIndex; }
@Override public void stringField(FieldInfo fieldInfo, String value) throws IOException { final FieldType ft = new FieldType(TextField.TYPE_STORED); ft.setStoreTermVectors(fieldInfo.hasVectors()); ft.setIndexed(fieldInfo.isIndexed()); ft.setOmitNorms(fieldInfo.omitsNorms()); ft.setIndexOptions(fieldInfo.getIndexOptions()); doc.add(new Field(fieldInfo.name, value, ft)); }
private BinaryDocValues loadBytesFixedStraight(FieldInfo field) throws IOException { String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "dat"); IndexInput input = dir.openInput(fileName, state.context); boolean success = false; try { CodecUtil.checkHeader(input, Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_CODEC_NAME, Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_VERSION_START, Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_VERSION_CURRENT); final int fixedLength = input.readInt(); PagedBytes bytes = new PagedBytes(16); bytes.copy(input, fixedLength * (long)state.segmentInfo.getDocCount()); final PagedBytes.Reader bytesReader = bytes.freeze(true); CodecUtil.checkEOF(input); success = true; ramBytesUsed.addAndGet(bytesReader.ramBytesUsed()); return new BinaryDocValues() { @Override public BytesRef get(int docID) { final BytesRef term = new BytesRef(); bytesReader.fillSlice(term, fixedLength * (long)docID, fixedLength); return term; } }; } finally { if (success) { IOUtils.close(input); } else { IOUtils.closeWhileHandlingException(input); } } }