Class UnifiedHighlighter.Builder
java.lang.Object
org.apache.lucene.search.uhighlight.UnifiedHighlighter.Builder
- Enclosing class:
UnifiedHighlighter
Builder for UnifiedHighlighter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Supplier
<BreakIterator> BreakIterator is stateful so we use a Supplier factory method.private int
private Set
<UnifiedHighlighter.HighlightFlag> private PassageFormatter
private boolean
private boolean
private final Analyzer
private int
private int
private boolean
private PassageScorer
private final IndexSearcher
If null, can only use highlightWithoutSearcher.private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionBuilder
(IndexSearcher searcher, Analyzer indexAnalyzer) Constructor for UH builder which acceptsIndexSearcher
andAnalyzer
objects. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
getFlags()
......withBreakIterator
(Supplier<BreakIterator> value) withCacheFieldValCharsThreshold
(int value) withFieldMatcher
(Predicate<String> value) withFlags
(Set<UnifiedHighlighter.HighlightFlag> values) User-defined set ofUnifiedHighlighter.HighlightFlag
values which will override the flags set bywithHandleMultiTermQuery(boolean)
,withHighlightPhrasesStrictly(boolean)
,withPassageRelevancyOverSpeed(boolean)
andwithWeightMatches(boolean)
.withFormatter
(PassageFormatter value) withHandleMultiTermQuery
(boolean value) HereMultiTermQuery
derivatives will be highlighted.withHighlightPhrasesStrictly
(boolean value) Here position sensitive queries (e.g.withMaxLength
(int value) The text to be highlight is effectively truncated by this length.withMaxNoHighlightPassages
(int value) withPassageRelevancyOverSpeed
(boolean value) Passage relevancy is more important than speed.withScorer
(PassageScorer value) withWeightMatches
(boolean value) Internally use theWeight.matches(LeafReaderContext, int)
API for highlighting.
-
Field Details
-
searcher
If null, can only use highlightWithoutSearcher. -
indexAnalyzer
-
fieldMatcher
-
flags
-
handleMultiTermQuery
private boolean handleMultiTermQuery -
highlightPhrasesStrictly
private boolean highlightPhrasesStrictly -
passageRelevancyOverSpeed
private boolean passageRelevancyOverSpeed -
weightMatches
private boolean weightMatches -
maxLength
private int maxLength -
breakIterator
BreakIterator is stateful so we use a Supplier factory method. -
scorer
-
formatter
-
maxNoHighlightPassages
private int maxNoHighlightPassages -
cacheFieldValCharsThreshold
private int cacheFieldValCharsThreshold
-
-
Constructor Details
-
Builder
Constructor for UH builder which acceptsIndexSearcher
andAnalyzer
objects.IndexSearcher
object can only be null whenUnifiedHighlighter.highlightWithoutSearcher(String, Query, String, int)
is used.- Parameters:
searcher
- -IndexSearcher
indexAnalyzer
- -Analyzer
-
-
Method Details
-
withFlags
User-defined set ofUnifiedHighlighter.HighlightFlag
values which will override the flags set bywithHandleMultiTermQuery(boolean)
,withHighlightPhrasesStrictly(boolean)
,withPassageRelevancyOverSpeed(boolean)
andwithWeightMatches(boolean)
.Here the user can either specify the set of
UnifiedHighlighter.HighlightFlag
s to be applied or use the boolean flags to populate final list ofUnifiedHighlighter.HighlightFlag
s.- Parameters:
values
- - set ofUnifiedHighlighter.HighlightFlag
values.
-
withHighlightPhrasesStrictly
Here position sensitive queries (e.g. phrases andSpanQuery
ies) are highlighted strictly based on query matches (slower) versus any/all occurrences of the underlying terms. By default it's enabled, but there's no overhead if such queries aren't used. -
withHandleMultiTermQuery
HereMultiTermQuery
derivatives will be highlighted. By default it's enabled. MTQ highlighting can be expensive, particularly when using offsets in postings. -
withPassageRelevancyOverSpeed
Passage relevancy is more important than speed. True by default. -
withWeightMatches
Internally use theWeight.matches(LeafReaderContext, int)
API for highlighting. It's more accurate to the query, and the snippets can be a little different for phrases because the whole phrase is marked up instead of each word. The passage relevancy calculation can be different (maybe worse?) and it's slower when highlighting many fields. Use of this flag requiresUnifiedHighlighter.HighlightFlag.MULTI_TERM_QUERY
andUnifiedHighlighter.HighlightFlag.PHRASES
andUnifiedHighlighter.HighlightFlag.PASSAGE_RELEVANCY_OVER_SPEED
. True by default because those booleans are true by default. -
withMaxLength
The text to be highlight is effectively truncated by this length. -
withBreakIterator
-
withFieldMatcher
-
withScorer
-
withFormatter
-
withMaxNoHighlightPassages
-
withCacheFieldValCharsThreshold
-
build
-
getIndexSearcher
... as passed in from the Builder constructor. -
getIndexAnalyzer
... as passed in from the Builder constructor. -
getFlags
-