Module org.apache.lucene.suggest
Class ExternalRefSorter
- java.lang.Object
-
- org.apache.lucene.search.suggest.fst.ExternalRefSorter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,BytesRefSorter
public class ExternalRefSorter extends java.lang.Object implements BytesRefSorter, java.io.Closeable
An implementation of aBytesRefSorter
that allows appendingBytesRef
s to anOfflineSorter
and returns aCloseable
ExternalRefSorter.ByteSequenceIterator
that iterates over sequences stored on disk.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExternalRefSorter.ByteSequenceIterator
Iterates overBytesRef
s in a file, closes the reader when the iterator is exhausted.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
sortedOutput
private OfflineSorter
sorter
private IndexOutput
tempOutput
private OfflineSorter.ByteSequencesWriter
writer
-
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 void
add(BytesRef utf8)
Adds a single suggestion entry (possibly compound with its bucket).void
close()
Close the writer and remove any temporary files.private void
closeWriter()
Close the writer but leave any sorted output for iteration.java.util.Comparator<BytesRef>
getComparator()
Comparator used to determine the sort order of entries.ExternalRefSorter.ByteSequenceIterator
iterator()
Sorts the entries added inBytesRefSorter.add(BytesRef)
and returns an iterator over all sorted entries.
-
-
-
Field Detail
-
sorter
private final OfflineSorter sorter
-
writer
private OfflineSorter.ByteSequencesWriter writer
-
tempOutput
private IndexOutput tempOutput
-
sortedOutput
private java.lang.String sortedOutput
-
-
Constructor Detail
-
ExternalRefSorter
public ExternalRefSorter(OfflineSorter sorter) throws java.io.IOException
Will buffer all sequences to a temporary file and then sort (all on-disk).- Throws:
java.io.IOException
-
-
Method Detail
-
add
public void add(BytesRef utf8) throws java.io.IOException
Description copied from interface:BytesRefSorter
Adds a single suggestion entry (possibly compound with its bucket).- Specified by:
add
in interfaceBytesRefSorter
- Throws:
java.io.IOException
- If an I/O exception occurs.
-
iterator
public ExternalRefSorter.ByteSequenceIterator iterator() throws java.io.IOException
Description copied from interface:BytesRefSorter
Sorts the entries added inBytesRefSorter.add(BytesRef)
and returns an iterator over all sorted entries.- Specified by:
iterator
in interfaceBytesRefSorter
- Returns:
- Returns a
ExternalRefSorter.ByteSequenceIterator
that implementsBytesRefIterator
but is alsoCloseable
, ensuring any temporary resources are cleaned up if the iterator is either exhausted or closed. - Throws:
java.io.IOException
- If an I/O exception occurs.
-
closeWriter
private void closeWriter() throws java.io.IOException
Close the writer but leave any sorted output for iteration.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Close the writer and remove any temporary files.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
getComparator
public java.util.Comparator<BytesRef> getComparator()
Description copied from interface:BytesRefSorter
Comparator used to determine the sort order of entries.- Specified by:
getComparator
in interfaceBytesRefSorter
- Returns:
- Return the
Comparator
of theOfflineSorter
used to sort byte sequences.
-
-