Class MatchRegionRetriever
- java.lang.Object
-
- org.apache.lucene.search.matchhighlight.MatchRegionRetriever
-
public class MatchRegionRetriever extends java.lang.Object
Utility class to compute a list of "match regions" for a given query, searcher and document(s) usingMatches
API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MatchRegionRetriever.DocumentFieldValueProvider
ImplementsMatchRegionRetriever.FieldValueProvider
wrapping a preloadedDocument
.static interface
MatchRegionRetriever.FieldValueProvider
An abstraction that provides document values for a given field.static interface
MatchRegionRetriever.MatchOffsetsConsumer
A callback for accepting a single document (and its associated leaf reader, leaf document ID) and its match offset ranges, as indicated by theMatches
interface retrieved for the query.
-
Field Summary
Fields Modifier and Type Field Description private java.util.TreeSet<java.lang.String>
affectedFields
private java.util.List<LeafReaderContext>
leaves
private java.util.Map<java.lang.String,OffsetsRetrievalStrategy>
offsetStrategies
private java.util.Set<java.lang.String>
preloadFields
private Weight
weight
-
Constructor Summary
Constructors Constructor Description MatchRegionRetriever(IndexSearcher searcher, Query query, Analyzer analyzer)
A constructor with the default offset strategy supplier.MatchRegionRetriever(IndexSearcher searcher, Query query, OffsetsRetrievalStrategySupplier fieldOffsetStrategySupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkOrderConsistency(java.util.List<LeafReaderContext> leaves)
static OffsetsRetrievalStrategySupplier
computeOffsetRetrievalStrategies(IndexReader reader, Analyzer analyzer)
Compute default strategies for retrieving offsets fromMatchesIterator
instances for a set of given fields.void
highlightDocument(LeafReaderContext leafReaderContext, int contextDocId, MatchRegionRetriever.FieldValueProvider doc, java.util.function.Predicate<java.lang.String> acceptField, java.util.Map<java.lang.String,java.util.List<OffsetRange>> outputHighlights)
Low-level method for retrieving hit ranges for a single document.void
highlightDocuments(java.util.PrimitiveIterator.OfInt docIds, MatchRegionRetriever.MatchOffsetsConsumer consumer)
Low-level, high-efficiency method for highlighting large numbers of documents at once in a streaming fashion.void
highlightDocuments(TopDocs topDocs, MatchRegionRetriever.MatchOffsetsConsumer consumer)
-
-
-
Field Detail
-
leaves
private final java.util.List<LeafReaderContext> leaves
-
weight
private final Weight weight
-
affectedFields
private final java.util.TreeSet<java.lang.String> affectedFields
-
offsetStrategies
private final java.util.Map<java.lang.String,OffsetsRetrievalStrategy> offsetStrategies
-
preloadFields
private final java.util.Set<java.lang.String> preloadFields
-
-
Constructor Detail
-
MatchRegionRetriever
public MatchRegionRetriever(IndexSearcher searcher, Query query, Analyzer analyzer) throws java.io.IOException
A constructor with the default offset strategy supplier.- Parameters:
analyzer
- An analyzer that may be used to reprocess (retokenize) document fields in the absence of position offsets in the index. Note that the analyzer must return tokens (positions and offsets) identical to the ones stored in the index.- Throws:
java.io.IOException
-
MatchRegionRetriever
public MatchRegionRetriever(IndexSearcher searcher, Query query, OffsetsRetrievalStrategySupplier fieldOffsetStrategySupplier) throws java.io.IOException
- Parameters:
searcher
- Index searcher to be used for retrieving matches.query
- The query for which matches should be retrieved. The query should be rewritten against the provided searcher.fieldOffsetStrategySupplier
- A custom supplier of per-fieldOffsetsRetrievalStrategy
instances.- Throws:
java.io.IOException
-
-
Method Detail
-
highlightDocuments
public void highlightDocuments(TopDocs topDocs, MatchRegionRetriever.MatchOffsetsConsumer consumer) throws java.io.IOException
- Throws:
java.io.IOException
-
highlightDocuments
public void highlightDocuments(java.util.PrimitiveIterator.OfInt docIds, MatchRegionRetriever.MatchOffsetsConsumer consumer) throws java.io.IOException
Low-level, high-efficiency method for highlighting large numbers of documents at once in a streaming fashion.- Parameters:
docIds
- A stream of sorted document identifiers for which hit ranges should be returned.consumer
- A streaming consumer for document-hits pairs.- Throws:
java.io.IOException
-
highlightDocument
public void highlightDocument(LeafReaderContext leafReaderContext, int contextDocId, MatchRegionRetriever.FieldValueProvider doc, java.util.function.Predicate<java.lang.String> acceptField, java.util.Map<java.lang.String,java.util.List<OffsetRange>> outputHighlights) throws java.io.IOException
Low-level method for retrieving hit ranges for a single document. This method can be used with custom documentMatchRegionRetriever.FieldValueProvider
.- Throws:
java.io.IOException
-
checkOrderConsistency
private boolean checkOrderConsistency(java.util.List<LeafReaderContext> leaves)
-
computeOffsetRetrievalStrategies
public static OffsetsRetrievalStrategySupplier computeOffsetRetrievalStrategies(IndexReader reader, Analyzer analyzer)
Compute default strategies for retrieving offsets fromMatchesIterator
instances for a set of given fields.
-
-