java.lang.Object
org.elasticsearch.common.lucene.Lucene

public class Lucene extends Object
  • Field Details

    • LATEST_CODEC

      public static final String LATEST_CODEC
      See Also:
    • SOFT_DELETES_FIELD

      public static final String SOFT_DELETES_FIELD
      See Also:
    • STANDARD_ANALYZER

      public static final NamedAnalyzer STANDARD_ANALYZER
    • KEYWORD_ANALYZER

      public static final NamedAnalyzer KEYWORD_ANALYZER
    • WHITESPACE_ANALYZER

      public static final NamedAnalyzer WHITESPACE_ANALYZER
    • EMPTY_SCORE_DOCS

      public static final org.apache.lucene.search.ScoreDoc[] EMPTY_SCORE_DOCS
    • TOTAL_HITS_EQUAL_TO_ZERO

      public static final org.apache.lucene.search.TotalHits TOTAL_HITS_EQUAL_TO_ZERO
    • TOTAL_HITS_GREATER_OR_EQUAL_TO_ZERO

      public static final org.apache.lucene.search.TotalHits TOTAL_HITS_GREATER_OR_EQUAL_TO_ZERO
    • EMPTY_TOP_DOCS

      public static final org.apache.lucene.search.TopDocs EMPTY_TOP_DOCS
  • Method Details

    • files

      public static Iterable<String> files(org.apache.lucene.index.SegmentInfos infos) throws IOException
      Returns an iterable that allows to iterate over all files in this segments info
      Throws:
      IOException
    • getNumDocs

      public static int getNumDocs(org.apache.lucene.index.SegmentInfos info)
      Returns the number of documents in the index referenced by this SegmentInfos
    • readSegmentInfos

      public static org.apache.lucene.index.SegmentInfos readSegmentInfos(org.apache.lucene.store.Directory directory) throws IOException
      Reads the segments infos, failing if it fails to load
      Throws:
      IOException
    • readSegmentInfos

      public static org.apache.lucene.index.SegmentInfos readSegmentInfos(org.apache.lucene.index.IndexCommit commit) throws IOException
      Reads the segments infos from the given commit, failing if it fails to load
      Throws:
      IOException
    • pruneUnreferencedFiles

      public static org.apache.lucene.index.SegmentInfos pruneUnreferencedFiles(String segmentsFileName, org.apache.lucene.store.Directory directory) throws IOException
      This method removes all files from the given directory that are not referenced by the given segments file. This method will open an IndexWriter and relies on index file deleter to remove all unreferenced files. Segment files that are newer than the given segments file are removed forcefully to prevent problems with IndexWriter opening a potentially broken commit point / leftover. Note: this method will fail if there is another IndexWriter open on the given directory. This method will also acquire a write lock from the directory while pruning unused files. This method expects an existing index in the given directory that has the given segments file.
      Throws:
      IOException
    • getIndexCommit

      public static org.apache.lucene.index.IndexCommit getIndexCommit(org.apache.lucene.index.SegmentInfos si, org.apache.lucene.store.Directory directory) throws IOException
      Returns an index commit for the given SegmentInfos in the given directory.
      Throws:
      IOException
    • cleanLuceneIndex

      public static void cleanLuceneIndex(org.apache.lucene.store.Directory directory) throws IOException
      This method removes all lucene files from the given directory. It will first try to delete all commit points / segments files to ensure broken commits or corrupted indices will not be opened in the future. If any of the segment files can't be deleted this operation fails.
      Throws:
      IOException
    • checkSegmentInfoIntegrity

      public static void checkSegmentInfoIntegrity(org.apache.lucene.store.Directory directory) throws IOException
      Throws:
      IOException
    • exists

      public static boolean exists(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query) throws IOException
      Check whether there is one or more documents matching the provided query.
      Throws:
      IOException
    • readTotalHits

      public static org.apache.lucene.search.TotalHits readTotalHits(StreamInput in) throws IOException
      Throws:
      IOException
    • readTopDocs

      public static TopDocsAndMaxScore readTopDocs(StreamInput in) throws IOException
      Throws:
      IOException
    • readFieldDoc

      public static org.apache.lucene.search.FieldDoc readFieldDoc(StreamInput in) throws IOException
      Throws:
      IOException
    • readSortValues

      public static Object[] readSortValues(StreamInput in) throws IOException
      Throws:
      IOException
    • readSortValue

      public static Comparable<?> readSortValue(StreamInput in) throws IOException
      Throws:
      IOException
    • readScoreDoc

      public static org.apache.lucene.search.ScoreDoc readScoreDoc(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTotalHits

      public static void writeTotalHits(StreamOutput out, org.apache.lucene.search.TotalHits totalHits) throws IOException
      Throws:
      IOException
    • writeTopDocsIncludingShardIndex

      public static void writeTopDocsIncludingShardIndex(StreamOutput out, org.apache.lucene.search.TopDocs topDocs) throws IOException
      Same as writeTopDocs(org.elasticsearch.common.io.stream.StreamOutput, org.elasticsearch.common.lucene.search.TopDocsAndMaxScore) but also reads the shard index with every score doc written so that the results can be partitioned by shard for sorting purposes.
      Throws:
      IOException
    • writeSortFieldArray

      public static void writeSortFieldArray(StreamOutput out, org.apache.lucene.search.SortField[] sortFields) throws IOException
      Throws:
      IOException
    • readTopDocsIncludingShardIndex

      public static org.apache.lucene.search.TopDocs readTopDocsIncludingShardIndex(StreamInput in) throws IOException
      Read side counterpart to writeTopDocsIncludingShardIndex(org.elasticsearch.common.io.stream.StreamOutput, org.apache.lucene.search.TopDocs) and the same as readTopDocs(StreamInput) but for the added shard index values that are read.
      Throws:
      IOException
    • readSortFieldArray

      public static org.apache.lucene.search.SortField[] readSortFieldArray(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTopDocs

      public static void writeTopDocs(StreamOutput out, TopDocsAndMaxScore topDocs) throws IOException
      Throws:
      IOException
    • writeSortValue

      public static void writeSortValue(StreamOutput out, Object field) throws IOException
      Throws:
      IOException
    • writeFieldDoc

      public static void writeFieldDoc(StreamOutput out, org.apache.lucene.search.FieldDoc fieldDoc) throws IOException
      Throws:
      IOException
    • writeScoreDoc

      public static void writeScoreDoc(StreamOutput out, org.apache.lucene.search.ScoreDoc scoreDoc) throws IOException
      Throws:
      IOException
    • readSortType

      public static org.apache.lucene.search.SortField.Type readSortType(StreamInput in) throws IOException
      Throws:
      IOException
    • readSortField

      public static org.apache.lucene.search.SortField readSortField(StreamInput in) throws IOException
      Throws:
      IOException
    • writeSortType

      public static void writeSortType(StreamOutput out, org.apache.lucene.search.SortField.Type sortType) throws IOException
      Throws:
      IOException
    • readExplanation

      public static org.apache.lucene.search.Explanation readExplanation(StreamInput in) throws IOException
      Throws:
      IOException
    • writeExplanation

      public static void writeExplanation(StreamOutput out, org.apache.lucene.search.Explanation explanation) throws IOException
      Throws:
      IOException
    • indexExists

      public static boolean indexExists(org.apache.lucene.store.Directory directory) throws IOException
      Throws:
      IOException
    • isCorruptionException

      public static boolean isCorruptionException(Throwable t)
      Returns true iff the given exception or one of it's causes is an instance of CorruptIndexException, IndexFormatTooOldException, or IndexFormatTooNewException otherwise false.
    • parseVersionLenient

      public static org.apache.lucene.util.Version parseVersionLenient(String toParse, org.apache.lucene.util.Version defaultValue)
      Parses the version string lenient and returns the default value if the given string is null or empty
    • segmentReader

      public static org.apache.lucene.index.SegmentReader segmentReader(org.apache.lucene.index.LeafReader reader)
      Tries to extract a segment reader from the given index reader. If no SegmentReader can be extracted an IllegalStateException is thrown.
    • asSequentialAccessBits

      public static org.apache.lucene.util.Bits asSequentialAccessBits(int maxDoc, @Nullable org.apache.lucene.search.ScorerSupplier scorerSupplier) throws IOException
      Return a Bits view of the provided scorer. NOTE: that the returned Bits instance MUST be consumed in order.
      Throws:
      IOException
      See Also:
    • asSequentialAccessBits

      public static org.apache.lucene.util.Bits asSequentialAccessBits(int maxDoc, @Nullable org.apache.lucene.search.ScorerSupplier scorerSupplier, long estimatedGetCount) throws IOException
      Given a ScorerSupplier, return a Bits instance that will match all documents contained in the set. NOTE: that the returned Bits instance MUST be consumed in order.
      Parameters:
      estimatedGetCount - an estimation of the number of times that Bits.get(int) will get called
      Throws:
      IOException
    • canEarlyTerminate

      public static boolean canEarlyTerminate(org.apache.lucene.search.Sort searchSort, org.apache.lucene.search.Sort indexSort)
      Whether a query sorted by searchSort can be early-terminated if the index is sorted by indexSort.
    • wrapAllDocsLive

      public static org.apache.lucene.index.DirectoryReader wrapAllDocsLive(org.apache.lucene.index.DirectoryReader in) throws IOException
      Wraps a directory reader to make all documents live except those were rolled back or hard-deleted due to non-aborting exceptions during indexing. The wrapped reader can be used to query all documents.
      Parameters:
      in - the input directory reader
      Returns:
      the wrapped reader
      Throws:
      IOException
    • newSoftDeletesField

      public static org.apache.lucene.document.NumericDocValuesField newSoftDeletesField()
      Returns a numeric docvalues which can be used to soft-delete documents.
    • indexWriterConfigWithNoMerging

      public static org.apache.lucene.index.IndexWriterConfig indexWriterConfigWithNoMerging(org.apache.lucene.analysis.Analyzer analyzer)
      Prepares a new IndexWriterConfig that does not do any merges, by setting both the merge policy and the merge scheduler. Setting just the merge policy means that constructing the index writer will create a ConcurrentMergeScheduler by default, which is quite heavyweight.