Class MatchHighlighter
- java.lang.Object
-
- org.apache.lucene.search.matchhighlight.MatchHighlighter
-
public class MatchHighlighter extends java.lang.Object
An example highlighter that combines several lower-level highlighting utilities in this package into a fully featured, ready-to-use component.Note that if you need to customize or tweak the details of highlighting, it is better to assemble your own highlighter using those low-level building blocks, rather than extend or modify this one.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MatchHighlighter.DocHighlights
Single document's highlights.private static class
MatchHighlighter.DocHit
static interface
MatchHighlighter.FieldValueHighlighter
Actual per-field highlighter.static class
MatchHighlighter.QueryOffsetRange
AnOffsetRange
of a match, together with the source query that caused it.
-
Field Summary
Fields Modifier and Type Field Description private Analyzer
analyzer
private java.util.List<MatchHighlighter.FieldValueHighlighter>
fieldHighlighters
private java.util.HashSet<java.lang.String>
fieldsAlwaysReturned
private OffsetsRetrievalStrategySupplier
offsetsRetrievalStrategies
private IndexSearcher
searcher
-
Constructor Summary
Constructors Constructor Description MatchHighlighter(IndexSearcher searcher, Analyzer analyzer)
MatchHighlighter(IndexSearcher searcher, Analyzer analyzer, OffsetsRetrievalStrategySupplier offsetsRetrievalStrategies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
alwaysFetchFields(java.lang.String... fields)
Always fetch the given set of fields for all input documents.MatchHighlighter
appendFieldHighlighter(MatchHighlighter.FieldValueHighlighter highlighter)
Append a new highlighter to field highlighters chain.private MatchHighlighter.DocHighlights
computeDocFieldValues(MatchHighlighter.DocHit docHit)
private java.util.List<OffsetRange>
computeValueRanges(java.lang.String field, java.lang.String[] values)
private java.lang.String
contiguousFieldValue(java.lang.String field, java.lang.String[] values)
private MatchHighlighter.FieldValueHighlighter
fieldValueHighlighter(java.lang.String field, boolean hasMatches)
java.util.stream.Stream<MatchHighlighter.DocHighlights>
highlight(TopDocs topDocs, Query... queries)
-
-
-
Field Detail
-
searcher
private final IndexSearcher searcher
-
offsetsRetrievalStrategies
private final OffsetsRetrievalStrategySupplier offsetsRetrievalStrategies
-
analyzer
private final Analyzer analyzer
-
fieldsAlwaysReturned
private final java.util.HashSet<java.lang.String> fieldsAlwaysReturned
-
fieldHighlighters
private final java.util.List<MatchHighlighter.FieldValueHighlighter> fieldHighlighters
-
-
Constructor Detail
-
MatchHighlighter
public MatchHighlighter(IndexSearcher searcher, Analyzer analyzer)
-
MatchHighlighter
public MatchHighlighter(IndexSearcher searcher, Analyzer analyzer, OffsetsRetrievalStrategySupplier offsetsRetrievalStrategies)
-
-
Method Detail
-
appendFieldHighlighter
public MatchHighlighter appendFieldHighlighter(MatchHighlighter.FieldValueHighlighter highlighter)
Append a new highlighter to field highlighters chain. The order of field highlighters is important (first-matching wins).
-
alwaysFetchFields
public void alwaysFetchFields(java.lang.String... fields)
Always fetch the given set of fields for all input documents.
-
highlight
public java.util.stream.Stream<MatchHighlighter.DocHighlights> highlight(TopDocs topDocs, Query... queries) throws java.io.IOException
- Throws:
java.io.IOException
-
computeDocFieldValues
private MatchHighlighter.DocHighlights computeDocFieldValues(MatchHighlighter.DocHit docHit)
-
computeValueRanges
private java.util.List<OffsetRange> computeValueRanges(java.lang.String field, java.lang.String[] values)
-
contiguousFieldValue
private java.lang.String contiguousFieldValue(java.lang.String field, java.lang.String[] values)
-
fieldValueHighlighter
private MatchHighlighter.FieldValueHighlighter fieldValueHighlighter(java.lang.String field, boolean hasMatches)
-
-