Class ExternalRefSorter
- java.lang.Object
-
- org.apache.lucene.search.suggest.fst.ExternalRefSorter
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BytesRefSorter
public class ExternalRefSorter extends Object implements BytesRefSorter, Closeable
An implementation of aBytesRefSorterthat allows appendingBytesRefs to anOfflineSorterand returns aCloseableExternalRefSorter.ByteSequenceIteratorthat iterates over sequences stored on disk.- WARNING: This API is experimental and might change in incompatible ways in the next release.
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExternalRefSorter.ByteSequenceIteratorIterates overBytesRefs in a file, closes the reader when the iterator is exhausted.
-
Constructor Summary
Constructors Constructor Description ExternalRefSorter(OfflineSorter sorter)Will buffer all sequences to a temporary file and then sort (all on-disk).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(BytesRef utf8)Adds a single suggestion entry (possibly compound with its bucket).voidclose()Close the writer and remove any temporary files.Comparator<BytesRef>getComparator()Comparator used to determine the sort order of entries.ExternalRefSorter.ByteSequenceIteratoriterator()Sorts the entries added inBytesRefSorter.add(BytesRef)and returns an iterator over all sorted entries.
-
-
-
Constructor Detail
-
ExternalRefSorter
public ExternalRefSorter(OfflineSorter sorter) throws IOException
Will buffer all sequences to a temporary file and then sort (all on-disk).- Throws:
IOException
-
-
Method Detail
-
add
public void add(BytesRef utf8) throws IOException
Description copied from interface:BytesRefSorterAdds a single suggestion entry (possibly compound with its bucket).- Specified by:
addin interfaceBytesRefSorter- Throws:
IOException- If an I/O exception occurs.
-
iterator
public ExternalRefSorter.ByteSequenceIterator iterator() throws IOException
Description copied from interface:BytesRefSorterSorts the entries added inBytesRefSorter.add(BytesRef)and returns an iterator over all sorted entries.- Specified by:
iteratorin interfaceBytesRefSorter- Returns:
- Returns a
ExternalRefSorter.ByteSequenceIteratorthat implementsBytesRefIteratorbut is alsoCloseable, ensuring any temporary resources are cleaned up if the iterator is either exhausted or closed. - Throws:
IOException- If an I/O exception occurs.
-
close
public void close() throws IOExceptionClose the writer and remove any temporary files.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getComparator
public Comparator<BytesRef> getComparator()
Description copied from interface:BytesRefSorterComparator used to determine the sort order of entries.- Specified by:
getComparatorin interfaceBytesRefSorter- Returns:
- Return the
Comparatorof theOfflineSorterused to sort byte sequences.
-
-