Package org.elasticsearch.common.lucene
Class Lucene
- java.lang.Object
-
- org.elasticsearch.common.lucene.Lucene
-
public class Lucene extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static ScoreDoc[]EMPTY_SCORE_DOCSstatic TopDocsEMPTY_TOP_DOCSstatic NamedAnalyzerKEYWORD_ANALYZERstatic StringLATEST_CODECstatic StringLATEST_DOC_VALUES_FORMATstatic StringLATEST_POSTINGS_FORMATstatic StringSOFT_DELETES_FIELDstatic NamedAnalyzerSTANDARD_ANALYZER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BitsasSequentialAccessBits(int maxDoc, ScorerSupplier scorerSupplier)Return aBitsview of the provided scorer.static BitsasSequentialAccessBits(int maxDoc, ScorerSupplier scorerSupplier, long estimatedGetCount)Given aScorerSupplier, return aBitsinstance that will match all documents contained in the set.static booleancanEarlyTerminate(Sort searchSort, Sort indexSort)Whether a query sorted bysearchSortcan be early-terminated if the index is sorted byindexSort.static voidcheckSegmentInfoIntegrity(Directory directory)static voidcleanLuceneIndex(Directory directory)This method removes all lucene files from the given directory.static LeafReaderemptyReader(int maxDoc)Returns an empty leaf reader with the given max docs.static booleanexists(IndexSearcher searcher, Query query)Check whether there is one or more documents matching the provided query.static Iterable<String>files(SegmentInfos infos)Returns an iterable that allows to iterate over all files in this segments infostatic IndexCommitgetIndexCommit(SegmentInfos si, Directory directory)Returns an index commit for the givenSegmentInfosin the given directory.static intgetNumDocs(SegmentInfos info)Returns the number of documents in the index referenced by thisSegmentInfosstatic booleanindexExists(Directory directory)static booleanisCorruptionException(Throwable t)Returnstrueiff the given exception or one of it's causes is an instance ofCorruptIndexException,IndexFormatTooOldException, orIndexFormatTooNewExceptionotherwisefalse.static NumericDocValuesFieldnewSoftDeletesField()Returns a numeric docvalues which can be used to soft-delete documents.static VersionparseVersion(String version, Version defaultVersion, org.apache.logging.log4j.Logger logger)static VersionparseVersionLenient(String toParse, Version defaultValue)Parses the version string lenient and returns the default value if the given string is null or emptystatic SegmentInfospruneUnreferencedFiles(String segmentsFileName, Directory directory)This method removes all files from the given directory that are not referenced by the given segments file.static ExplanationreadExplanation(StreamInput in)static FieldDocreadFieldDoc(StreamInput in)static ScoreDocreadScoreDoc(StreamInput in)static SegmentInfosreadSegmentInfos(IndexCommit commit)Reads the segments infos from the given commit, failing if it fails to loadstatic SegmentInfosreadSegmentInfos(Directory directory)Reads the segments infos, failing if it fails to loadstatic SortFieldreadSortField(StreamInput in)static SortField.TypereadSortType(StreamInput in)static ComparablereadSortValue(StreamInput in)static TopDocsAndMaxScorereadTopDocs(StreamInput in)static TotalHitsreadTotalHits(StreamInput in)static SegmentReadersegmentReader(LeafReader reader)Tries to extract a segment reader from the given index reader.static booleanwaitForIndex(Directory directory, long timeLimitMillis)Wait for an index to exist for up totimeLimitMillis.static DirectoryReaderwrapAllDocsLive(DirectoryReader in)Wraps a directory reader to make all documents live except those were rolled back or hard-deleted due to non-aborting exceptions during indexing.static voidwriteExplanation(StreamOutput out, Explanation explanation)static voidwriteFieldDoc(StreamOutput out, FieldDoc fieldDoc)static voidwriteScoreDoc(StreamOutput out, ScoreDoc scoreDoc)static voidwriteSortField(StreamOutput out, SortField sortField)static voidwriteSortType(StreamOutput out, SortField.Type sortType)static voidwriteSortValue(StreamOutput out, Object field)static voidwriteTopDocs(StreamOutput out, TopDocsAndMaxScore topDocs)static voidwriteTotalHits(StreamOutput out, TotalHits totalHits)
-
-
-
Field Detail
-
LATEST_DOC_VALUES_FORMAT
public static final String LATEST_DOC_VALUES_FORMAT
- See Also:
- Constant Field Values
-
LATEST_POSTINGS_FORMAT
public static final String LATEST_POSTINGS_FORMAT
- See Also:
- Constant Field Values
-
LATEST_CODEC
public static final String LATEST_CODEC
- See Also:
- Constant Field Values
-
SOFT_DELETES_FIELD
public static final String SOFT_DELETES_FIELD
- See Also:
- Constant Field Values
-
STANDARD_ANALYZER
public static final NamedAnalyzer STANDARD_ANALYZER
-
KEYWORD_ANALYZER
public static final NamedAnalyzer KEYWORD_ANALYZER
-
EMPTY_SCORE_DOCS
public static final ScoreDoc[] EMPTY_SCORE_DOCS
-
EMPTY_TOP_DOCS
public static final TopDocs EMPTY_TOP_DOCS
-
-
Method Detail
-
parseVersion
public static Version parseVersion(@Nullable String version, Version defaultVersion, org.apache.logging.log4j.Logger logger)
-
readSegmentInfos
public static SegmentInfos readSegmentInfos(Directory directory) throws IOException
Reads the segments infos, failing if it fails to load- Throws:
IOException
-
files
public static Iterable<String> files(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(SegmentInfos info)
Returns the number of documents in the index referenced by thisSegmentInfos
-
readSegmentInfos
public static SegmentInfos readSegmentInfos(IndexCommit commit) throws IOException
Reads the segments infos from the given commit, failing if it fails to load- Throws:
IOException
-
pruneUnreferencedFiles
public static SegmentInfos pruneUnreferencedFiles(String segmentsFileName, 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 IndexCommit getIndexCommit(SegmentInfos si, Directory directory) throws IOException
Returns an index commit for the givenSegmentInfosin the given directory.- Throws:
IOException
-
cleanLuceneIndex
public static void cleanLuceneIndex(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(Directory directory) throws IOException
- Throws:
IOException
-
exists
public static boolean exists(IndexSearcher searcher, Query query) throws IOException
Check whether there is one or more documents matching the provided query.- Throws:
IOException
-
readTotalHits
public static TotalHits readTotalHits(StreamInput in) throws IOException
- Throws:
IOException
-
readTopDocs
public static TopDocsAndMaxScore readTopDocs(StreamInput in) throws IOException
- Throws:
IOException
-
readFieldDoc
public static FieldDoc readFieldDoc(StreamInput in) throws IOException
- Throws:
IOException
-
readSortValue
public static Comparable readSortValue(StreamInput in) throws IOException
- Throws:
IOException
-
readScoreDoc
public static ScoreDoc readScoreDoc(StreamInput in) throws IOException
- Throws:
IOException
-
writeTotalHits
public static void writeTotalHits(StreamOutput out, TotalHits totalHits) 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, FieldDoc fieldDoc) throws IOException
- Throws:
IOException
-
writeScoreDoc
public static void writeScoreDoc(StreamOutput out, ScoreDoc scoreDoc) throws IOException
- Throws:
IOException
-
readSortType
public static SortField.Type readSortType(StreamInput in) throws IOException
- Throws:
IOException
-
readSortField
public static SortField readSortField(StreamInput in) throws IOException
- Throws:
IOException
-
writeSortType
public static void writeSortType(StreamOutput out, SortField.Type sortType) throws IOException
- Throws:
IOException
-
writeSortField
public static void writeSortField(StreamOutput out, SortField sortField) throws IOException
- Throws:
IOException
-
readExplanation
public static Explanation readExplanation(StreamInput in) throws IOException
- Throws:
IOException
-
writeExplanation
public static void writeExplanation(StreamOutput out, Explanation explanation) throws IOException
- Throws:
IOException
-
indexExists
public static boolean indexExists(Directory directory) throws IOException
- Throws:
IOException
-
waitForIndex
public static boolean waitForIndex(Directory directory, long timeLimitMillis) throws IOException
Wait for an index to exist for up totimeLimitMillis. Returns true if the index eventually exists, false if not. Will retry the directory every second for at leasttimeLimitMillis- Throws:
IOException
-
isCorruptionException
public static boolean isCorruptionException(Throwable t)
Returnstrueiff the given exception or one of it's causes is an instance ofCorruptIndexException,IndexFormatTooOldException, orIndexFormatTooNewExceptionotherwisefalse.
-
parseVersionLenient
public static Version parseVersionLenient(String toParse, Version defaultValue)
Parses the version string lenient and returns the default value if the given string is null or empty
-
segmentReader
public static SegmentReader segmentReader(LeafReader reader)
Tries to extract a segment reader from the given index reader. If no SegmentReader can be extracted anIllegalStateExceptionis thrown.
-
asSequentialAccessBits
public static Bits asSequentialAccessBits(int maxDoc, @Nullable ScorerSupplier scorerSupplier) throws IOException
Return aBitsview of the provided scorer. NOTE: that the returnedBitsinstance MUST be consumed in order.- Throws:
IOException- See Also:
asSequentialAccessBits(int, ScorerSupplier, long)
-
asSequentialAccessBits
public static Bits asSequentialAccessBits(int maxDoc, @Nullable ScorerSupplier scorerSupplier, long estimatedGetCount) throws IOException
Given aScorerSupplier, return aBitsinstance that will match all documents contained in the set. NOTE: that the returnedBitsinstance MUST be consumed in order.- Parameters:
estimatedGetCount- an estimation of the number of times thatBits.get(int)will get called- Throws:
IOException
-
canEarlyTerminate
public static boolean canEarlyTerminate(Sort searchSort, Sort indexSort)
Whether a query sorted bysearchSortcan be early-terminated if the index is sorted byindexSort.
-
wrapAllDocsLive
public static DirectoryReader wrapAllDocsLive(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 NumericDocValuesField newSoftDeletesField()
Returns a numeric docvalues which can be used to soft-delete documents.
-
emptyReader
public static LeafReader emptyReader(int maxDoc)
Returns an empty leaf reader with the given max docs. The reader will be fully deleted.
-
-