Package org.apache.lucene.search.suggest
Class SortedInputIterator
- java.lang.Object
-
- org.apache.lucene.search.suggest.SortedInputIterator
-
- All Implemented Interfaces:
InputIterator
,BytesRefIterator
- Direct Known Subclasses:
WFSTCompletionLookup.WFSTInputIterator
public class SortedInputIterator extends java.lang.Object implements InputIterator
This wrapper buffers incoming elements and makes sure they are sorted based on given comparator.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.lucene.search.suggest.InputIterator
InputIterator.InputIteratorWrapper
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparator<BytesRef>
comparator
private java.util.Set<BytesRef>
contexts
private boolean
done
private boolean
hasContexts
private boolean
hasPayloads
private BytesRef
payload
private OfflineSorter.ByteSequencesReader
reader
private InputIterator
source
private Directory
tempDir
private java.lang.String
tempFileNamePrefix
private IndexOutput
tempInput
private java.lang.String
tempSortedFileName
private java.util.Comparator<BytesRef>
tieBreakByCostComparator
Sortes by BytesRef (ascending) then cost (ascending).private long
weight
-
Fields inherited from interface org.apache.lucene.search.suggest.InputIterator
EMPTY
-
-
Constructor Summary
Constructors Constructor Description SortedInputIterator(Directory tempDir, java.lang.String tempFileNamePrefix, InputIterator source)
Creates a new sorted wrapper, using natural order for sorting.SortedInputIterator(Directory tempDir, java.lang.String tempFileNamePrefix, InputIterator source, java.util.Comparator<BytesRef> comparator)
Creates a new sorted wrapper, sorting by BytesRef (ascending) then cost (ascending).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
close()
java.util.Set<BytesRef>
contexts()
A term's contexts context can be used to filter suggestions.protected long
decode(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the weight at the current positionprotected java.util.Set<BytesRef>
decodeContexts(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the contexts at the current positionprotected BytesRef
decodePayload(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the payload at the current positionprotected void
encode(OfflineSorter.ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, BytesRef payload, java.util.Set<BytesRef> contexts, long weight)
encodes an entry (bytes+(contexts)+(payload)+weight) to the provided writerboolean
hasContexts()
Returns true if the iterator has contextsboolean
hasPayloads()
Returns true if the iterator has payloadsBytesRef
next()
Increments the iteration to the nextBytesRef
in the iterator.BytesRef
payload()
An arbitrary byte[] to record per suggestion.private OfflineSorter.ByteSequencesReader
sort()
long
weight()
A term's weight, higher numbers mean better suggestions.
-
-
-
Field Detail
-
source
private final InputIterator source
-
tempInput
private IndexOutput tempInput
-
tempSortedFileName
private java.lang.String tempSortedFileName
-
reader
private final OfflineSorter.ByteSequencesReader reader
-
comparator
private final java.util.Comparator<BytesRef> comparator
-
hasPayloads
private final boolean hasPayloads
-
hasContexts
private final boolean hasContexts
-
tempDir
private final Directory tempDir
-
tempFileNamePrefix
private final java.lang.String tempFileNamePrefix
-
done
private boolean done
-
weight
private long weight
-
payload
private BytesRef payload
-
contexts
private java.util.Set<BytesRef> contexts
-
tieBreakByCostComparator
private final java.util.Comparator<BytesRef> tieBreakByCostComparator
Sortes by BytesRef (ascending) then cost (ascending).
-
-
Constructor Detail
-
SortedInputIterator
public SortedInputIterator(Directory tempDir, java.lang.String tempFileNamePrefix, InputIterator source) throws java.io.IOException
Creates a new sorted wrapper, using natural order for sorting.- Throws:
java.io.IOException
-
SortedInputIterator
public SortedInputIterator(Directory tempDir, java.lang.String tempFileNamePrefix, InputIterator source, java.util.Comparator<BytesRef> comparator) throws java.io.IOException
Creates a new sorted wrapper, sorting by BytesRef (ascending) then cost (ascending).- Throws:
java.io.IOException
-
-
Method Detail
-
next
public BytesRef next() throws java.io.IOException
Description copied from interface:BytesRefIterator
Increments the iteration to the nextBytesRef
in the iterator. Returns the resultingBytesRef
ornull
if the end of the iterator is reached. The returned BytesRef may be re-used across calls to next. After this method returns null, do not call it again: the results are undefined.- Specified by:
next
in interfaceBytesRefIterator
- Returns:
- the next
BytesRef
in the iterator ornull
if the end of the iterator is reached. - Throws:
java.io.IOException
- If there is a low-level I/O error.
-
weight
public long weight()
Description copied from interface:InputIterator
A term's weight, higher numbers mean better suggestions.- Specified by:
weight
in interfaceInputIterator
-
payload
public BytesRef payload()
Description copied from interface:InputIterator
An arbitrary byte[] to record per suggestion. SeeLookup.LookupResult.payload
to retrieve the payload for each suggestion.- Specified by:
payload
in interfaceInputIterator
-
hasPayloads
public boolean hasPayloads()
Description copied from interface:InputIterator
Returns true if the iterator has payloads- Specified by:
hasPayloads
in interfaceInputIterator
-
contexts
public java.util.Set<BytesRef> contexts()
Description copied from interface:InputIterator
A term's contexts context can be used to filter suggestions. May return null, if suggest entries do not have any context- Specified by:
contexts
in interfaceInputIterator
-
hasContexts
public boolean hasContexts()
Description copied from interface:InputIterator
Returns true if the iterator has contexts- Specified by:
hasContexts
in interfaceInputIterator
-
sort
private OfflineSorter.ByteSequencesReader sort() throws java.io.IOException
- Throws:
java.io.IOException
-
close
private void close() throws java.io.IOException
- Throws:
java.io.IOException
-
encode
protected void encode(OfflineSorter.ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, BytesRef payload, java.util.Set<BytesRef> contexts, long weight) throws java.io.IOException
encodes an entry (bytes+(contexts)+(payload)+weight) to the provided writer- Throws:
java.io.IOException
-
decode
protected long decode(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the weight at the current position
-
decodeContexts
protected java.util.Set<BytesRef> decodeContexts(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the contexts at the current position
-
decodePayload
protected BytesRef decodePayload(BytesRef scratch, ByteArrayDataInput tmpInput)
decodes the payload at the current position
-
-