/** helper: checks a fieldinfo and throws exception if its definitely not a LatLonDocValuesField */ static void checkCompatible(FieldInfo fieldInfo) { // dv properties could be "unset", if you e.g. used only StoredField with this same name in the segment. if (fieldInfo.getDocValuesType() != DocValuesType.NONE && fieldInfo.getDocValuesType() != TYPE.docValuesType()) { throw new IllegalArgumentException("field=\"" + fieldInfo.name + "\" was indexed with docValuesType=" + fieldInfo.getDocValuesType() + " but this type has docValuesType=" + TYPE.docValuesType() + ", is the field really a LatLonDocValuesField?"); } }
private FieldInfo getDVField(String field, DocValuesType type) { FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() == DocValuesType.NONE) { // Field was not indexed with doc values return null; } if (fi.getDocValuesType() != type) { // Field DocValues are different than requested type return null; } return fi; }
private static void checkField(LeafReader in, String field, DocValuesType... expected) { FieldInfo fi = in.getFieldInfos().fieldInfo(field); if (fi != null) { DocValuesType actual = fi.getDocValuesType(); throw new IllegalStateException("unexpected docvalues type " + actual + " for field '" + field + "' " + (expected.length == 1 ? "(expected=" + expected[0] : "(expected one of " + Arrays.toString(expected)) + "). " + "Re-index with correct docvalues type."); } }
@Override DocIdSetIterator getHasDocValues(String field) { PerField perField = getPerField(field); if (perField != null) { if (perField.docValuesWriter != null) { if (perField.fieldInfo.getDocValuesType() == DocValuesType.NONE) { return null; } return perField.docValuesWriter.getDocIdSet(); } } return null; } }
/** * @return the {@code NumericDocValues} for a given field * @throws IllegalArgumentException if this field is not indexed with numeric doc values */ public NumericDocValues readDocValues( String field ) { try { NumericDocValues dv = context.reader().getNumericDocValues( field ); if ( dv == null ) { FieldInfo fi = context.reader().getFieldInfos().fieldInfo( field ); DocValuesType actual = null; if ( fi != null ) { actual = fi.getDocValuesType(); } throw new IllegalStateException( "The field '" + field + "' is not indexed properly, expected NumericDV, but got '" + actual + "'" ); } return dv; } catch ( IOException e ) { throw new RuntimeException( e ); } } }
@Override public SortedNumericDocValues getSortedNumericDocValues(String field) throws IOException { ensureOpen(); FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() != DocValuesType.SORTED_NUMERIC) { // Field was not indexed with doc values return null; } return docValues.getSortedNumeric(fi); }
@Override public SortedSetDocValues getSortedSetDocValues(String field) throws IOException { ensureOpen(); FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() != DocValuesType.SORTED_SET) { // Field was not indexed with doc values return null; } return docValues.getSortedSet(fi); }
if (fi.getDocValuesType() != DocValuesType.NONE) { final String fieldName = fi.name; final String formatName = fi.getAttribute(PER_FIELD_FORMAT_KEY);
@Override public SortedDocValues getSortedDocValues(String field) throws IOException { ensureOpen(); FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() != DocValuesType.SORTED) { // Field was not indexed with doc values return null; } return docValues.getSorted(fi); }
@Override public NumericDocValues getNumericDocValues(String field) throws IOException { ensureOpen(); FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() != DocValuesType.NUMERIC) { // Field was not indexed with doc values return null; } return docValues.getNumeric(fi); }
@Override public BinaryDocValues getBinaryDocValues(String field) throws IOException { ensureOpen(); FieldInfo fi = getFieldInfos().fieldInfo(field); if (fi == null) { // Field does not exist return null; } if (fi.getDocValuesType() != DocValuesType.BINARY) { // Field was not indexed with doc values return null; } return docValues.getBinary(fi); }
fieldTypes.put( fieldInfo.name, fieldInfo.getDocValuesType() );
hasOffsets |= fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; hasNorms |= fi.hasNorms(); hasDocValues |= fi.getDocValuesType() != DocValuesType.NONE; hasPayloads |= fi.hasPayloads(); hasPointValues |= (fi.getPointDataDimensionCount() != 0);
private void ensureInitialized(IOSupplier<CodecReader> readerIOSupplier) throws IOException { if (dvGeneration == -2) { FieldInfos fieldInfos = readFieldInfos(); FieldInfo fieldInfo = fieldInfos.fieldInfo(field); // we try to only open a reader if it's really necessary ie. indices that are mainly append only might have // big segments that don't even have any docs in the soft deletes field. In such a case it's simply // enough to look at the FieldInfo for the field and check if the field has DocValues if (fieldInfo != null && fieldInfo.getDocValuesType() != DocValuesType.NONE) { // in order to get accurate numbers we need to have a least one reader see here. onNewReader(readerIOSupplier.get(), info); } else { // we are safe here since we don't have any doc values for the soft-delete field on disk // no need to open a new reader dvGeneration = fieldInfo == null ? -1 : fieldInfo.getDocValuesGen(); } } }
/** * Loads or returns the already loaded the global field number map for this {@link SegmentInfos}. * If this {@link SegmentInfos} has no global field number map the returned instance is empty */ private FieldNumbers getFieldNumberMap() throws IOException { final FieldNumbers map = new FieldNumbers(config.softDeletesField); for(SegmentCommitInfo info : segmentInfos) { FieldInfos fis = readFieldInfos(info); for(FieldInfo fi : fis) { map.addOrGet(fi.name, fi.number, fi.getDocValuesType(), fi.getPointDataDimensionCount(), fi.getPointIndexDimensionCount(), fi.getPointNumBytes(), fi.isSoftDeletesField()); } } return map; }
final DocIdSetIterator iterator; if (fieldInfo != null) { switch (fieldInfo.getDocValuesType()) { case NONE: iterator = null;
public FieldInfo add(FieldInfo fi, long dvGen) { // IMPORTANT - reuse the field number if possible for consistent field numbers across segments return addOrUpdateInternal(fi.name, fi.number, fi.hasVectors(), fi.omitsNorms(), fi.hasPayloads(), fi.getIndexOptions(), fi.getDocValuesType(), dvGen, fi.getPointDataDimensionCount(), fi.getPointIndexDimensionCount(), fi.getPointNumBytes(), fi.isSoftDeletesField()); }
private static void checkDocValues(FieldInfo fi, DocValuesProducer dvReader, int maxDoc, PrintStream infoStream, DocValuesStatus status) throws Exception { switch(fi.getDocValuesType()) { case SORTED: status.totalSortedFields++;
@Override public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException { final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION); try (IndexOutput output = directory.createOutput(fileName, context)) { CodecUtil.writeIndexHeader(output, Lucene50FieldInfosFormat.CODEC_NAME, Lucene50FieldInfosFormat.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix); output.writeVInt(infos.size()); for (FieldInfo fi : infos) { fi.checkConsistency(); output.writeString(fi.name); output.writeVInt(fi.number); byte bits = 0x0; if (fi.hasVectors()) bits |= STORE_TERMVECTOR; if (fi.omitsNorms()) bits |= OMIT_NORMS; if (fi.hasPayloads()) bits |= STORE_PAYLOADS; output.writeByte(bits); output.writeByte(indexOptionsByte(fi.getIndexOptions())); // pack the DV type and hasNorms in one byte output.writeByte(docValuesByte(fi.getDocValuesType())); output.writeLong(fi.getDocValuesGen()); output.writeMapOfStrings(fi.attributes()); } CodecUtil.writeFooter(output); } }
output.writeByte(docValuesByte(fi.getDocValuesType())); output.writeLong(fi.getDocValuesGen()); output.writeMapOfStrings(fi.attributes());