All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.lucene.codecs.lucene70.Lucene70SegmentInfoFormat Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.lucene.codecs.lucene70;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedNumericSelector;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.search.SortedSetSelector;
import org.apache.lucene.search.SortedSetSortField;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.Version;

/**
 * Lucene 7.0 Segment info format.
 * 

* Files: *

    *
  • .si: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Attributes, IndexSort, Footer *
* Data types: *
    *
  • Header --> {@link CodecUtil#writeIndexHeader IndexHeader}
  • *
  • SegSize --> {@link DataOutput#writeInt Int32}
  • *
  • SegVersion --> {@link DataOutput#writeString String}
  • *
  • SegMinVersion --> {@link DataOutput#writeString String}
  • *
  • Files --> {@link DataOutput#writeSetOfStrings Set<String>}
  • *
  • Diagnostics,Attributes --> {@link DataOutput#writeMapOfStrings Map<String,String>}
  • *
  • IsCompoundFile --> {@link DataOutput#writeByte Int8}
  • *
  • IndexSort --> {@link DataOutput#writeVInt Int32} count, followed by {@code count} SortField
  • *
  • SortField --> {@link DataOutput#writeString String} field name, followed by {@link DataOutput#writeVInt Int32} sort type ID, * followed by {@link DataOutput#writeByte Int8} indicating reversed sort, followed by a type-specific encoding of the optional missing value *
  • Footer --> {@link CodecUtil#writeFooter CodecFooter}
  • *
* Field Descriptions: *
    *
  • SegVersion is the code version that created the segment.
  • *
  • SegMinVersion is the minimum code version that contributed documents to the segment.
  • *
  • SegSize is the number of documents contained in the segment index.
  • *
  • IsCompoundFile records whether the segment is written as a compound file or * not. If this is -1, the segment is not a compound file. If it is 1, the segment * is a compound file.
  • *
  • The Diagnostics Map is privately written by {@link IndexWriter}, as a debugging aid, * for each segment it creates. It includes metadata like the current Lucene * version, OS, Java version, why the segment was created (merge, flush, * addIndexes), etc.
  • *
  • Files is a list of files referred to by this segment.
  • *
* * @see SegmentInfos * @lucene.experimental */ public class Lucene70SegmentInfoFormat extends SegmentInfoFormat { /** Sole constructor. */ public Lucene70SegmentInfoFormat() { } @Override public SegmentInfo read(Directory dir, String segment, byte[] segmentID, IOContext context) throws IOException { final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene70SegmentInfoFormat.SI_EXTENSION); try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) { Throwable priorE = null; SegmentInfo si = null; try { int format = CodecUtil.checkIndexHeader(input, Lucene70SegmentInfoFormat.CODEC_NAME, Lucene70SegmentInfoFormat.VERSION_START, Lucene70SegmentInfoFormat.VERSION_CURRENT, segmentID, ""); final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt()); byte hasMinVersion = input.readByte(); final Version minVersion; switch (hasMinVersion) { case 0: minVersion = null; break; case 1: minVersion = Version.fromBits(input.readInt(), input.readInt(), input.readInt()); break; default: throw new CorruptIndexException("Illegal boolean value " + hasMinVersion, input); } final int docCount = input.readInt(); if (docCount < 0) { throw new CorruptIndexException("invalid docCount: " + docCount, input); } final boolean isCompoundFile = input.readByte() == SegmentInfo.YES; final Map diagnostics = input.readMapOfStrings(); final Set files = input.readSetOfStrings(); final Map attributes = input.readMapOfStrings(); int numSortFields = input.readVInt(); Sort indexSort; if (numSortFields > 0) { SortField[] sortFields = new SortField[numSortFields]; for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy