Class MatchRegionRetriever
- java.lang.Object
-
- org.apache.lucene.search.matchhighlight.MatchRegionRetriever
-
public class MatchRegionRetriever extends java.lang.ObjectUtility class to compute a list of "match regions" for a given query, searcher and document(s) usingMatchesAPI.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMatchRegionRetriever.DocumentFieldValueProviderImplementsMatchRegionRetriever.FieldValueProviderwrapping a preloadedDocument.static interfaceMatchRegionRetriever.FieldValueProviderAn abstraction that provides document values for a given field.static interfaceMatchRegionRetriever.MatchOffsetsConsumerA callback for accepting a single document (and its associated leaf reader, leaf document ID) and its match offset ranges, as indicated by theMatchesinterface retrieved for the query.
-
Field Summary
Fields Modifier and Type Field Description private java.util.TreeSet<java.lang.String>affectedFieldsprivate java.util.List<LeafReaderContext>leavesprivate java.util.Map<java.lang.String,OffsetsRetrievalStrategy>offsetStrategiesprivate java.util.Set<java.lang.String>preloadFieldsprivate Weightweight
-
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 booleancheckOrderConsistency(java.util.List<LeafReaderContext> leaves)static OffsetsRetrievalStrategySuppliercomputeOffsetRetrievalStrategies(IndexReader reader, Analyzer analyzer)Compute default strategies for retrieving offsets fromMatchesIteratorinstances for a set of given fields.voidhighlightDocument(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.voidhighlightDocuments(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.voidhighlightDocuments(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-fieldOffsetsRetrievalStrategyinstances.- 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.IOExceptionLow-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 fromMatchesIteratorinstances for a set of given fields.
-
-