Package org.apache.lucene.search.uhighlight

# Class UnifiedHighlighter.Builder

java.lang.Object
org.apache.lucene.search.uhighlight.UnifiedHighlighter.Builder

Enclosing class:
  `UnifiedHighlighter`

public static class UnifiedHighlighter.Builder extends Object
Builder for UnifiedHighlighter.

## Constructor Summary

Constructors
Constructor
Description
`Builder(IndexSearcher searcher, Analyzer indexAnalyzer)`
Constructor for UH builder which accepts `IndexSearcher` and `Analyzer` objects.

## Method Summary

Modifier and Type
Method
Description
`UnifiedHighlighter`
`build()`
`Set<UnifiedHighlighter.HighlightFlag>`
`getFlags()`
`Analyzer`
`getIndexAnalyzer()`
...
`IndexSearcher`
`getIndexSearcher()`
...
`UnifiedHighlighter.Builder`
`withBreakIterator(Supplier<BreakIterator> value)`
`UnifiedHighlighter.Builder`
`withCacheFieldValCharsThreshold(int value)`
`UnifiedHighlighter.Builder`
`withFieldMatcher(Predicate<String> value)`
`UnifiedHighlighter.Builder`
`withFlags(Set<UnifiedHighlighter.HighlightFlag> values)`
User-defined set of `UnifiedHighlighter.HighlightFlag` values which will override the flags set by `withHandleMultiTermQuery(boolean)`, `withHighlightPhrasesStrictly(boolean)`, `withPassageRelevancyOverSpeed(boolean)` and `withWeightMatches(boolean)`.
`UnifiedHighlighter.Builder`
`withFormatter(PassageFormatter value)`
`UnifiedHighlighter.Builder`
`withHandleMultiTermQuery(boolean value)`
Here `MultiTermQuery` derivatives will be highlighted.
`UnifiedHighlighter.Builder`
`withHighlightPhrasesStrictly(boolean value)`
Here position sensitive queries (e.g.
`UnifiedHighlighter.Builder`
`withMaskedFieldsFunc(Function<String,Set<String>> maskedFieldsFunc)`
Set up a function that given a field retuns a set of masked fields whose matches are combined to highlight the given field.
`UnifiedHighlighter.Builder`
`withMaxLength(int value)`
The text to be highlight is effectively truncated by this length.
`UnifiedHighlighter.Builder`
`withMaxNoHighlightPassages(int value)`
`UnifiedHighlighter.Builder`
`withPassageRelevancyOverSpeed(boolean value)`
Passage relevancy is more important than speed.
`UnifiedHighlighter.Builder`
`withPassageSortComparator(Comparator<Passage> value)`
`UnifiedHighlighter.Builder`
`withScorer(PassageScorer value)`
`UnifiedHighlighter.Builder`
`withWeightMatches(boolean value)`
Internally use the `Weight.matches(LeafReaderContext, int)` API for highlighting.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Builder

public Builder(IndexSearcher searcher, Analyzer indexAnalyzer)
Constructor for UH builder which accepts `IndexSearcher` and `Analyzer` objects. `IndexSearcher` object can only be null when `UnifiedHighlighter.highlightWithoutSearcher(String, Query, String, int)` is used.

Parameters:
  `searcher` - - `IndexSearcher`
  `indexAnalyzer` - - `Analyzer`

## Method Details

### withFlags

public UnifiedHighlighter.Builder withFlags(Set<UnifiedHighlighter.HighlightFlag> values)
User-defined set of `UnifiedHighlighter.HighlightFlag` values which will override the flags set by `withHandleMultiTermQuery(boolean)`, `withHighlightPhrasesStrictly(boolean)`, `withPassageRelevancyOverSpeed(boolean)` and `withWeightMatches(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 of `UnifiedHighlighter.HighlightFlag`s.

Parameters:
  `values` - - set of `UnifiedHighlighter.HighlightFlag` values.

### withHighlightPhrasesStrictly

public UnifiedHighlighter.Builder withHighlightPhrasesStrictly(boolean value)
Here position sensitive queries (e.g. phrases and `SpanQuery`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

public UnifiedHighlighter.Builder withHandleMultiTermQuery(boolean value)
Here `MultiTermQuery` derivatives will be highlighted. By default it's enabled. MTQ highlighting can be expensive, particularly when using offsets in postings.

### withPassageRelevancyOverSpeed

public UnifiedHighlighter.Builder withPassageRelevancyOverSpeed(boolean value)
Passage relevancy is more important than speed. True by default.

### withWeightMatches

public UnifiedHighlighter.Builder withWeightMatches(boolean value)
Internally use the `Weight.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 requires `UnifiedHighlighter.HighlightFlag.MULTI_TERM_QUERY` and `UnifiedHighlighter.HighlightFlag.PHRASES` and `UnifiedHighlighter.HighlightFlag.PASSAGE_RELEVANCY_OVER_SPEED`. True by default because those booleans are true by default.

### withMaxLength

public UnifiedHighlighter.Builder withMaxLength(int value)
The text to be highlight is effectively truncated by this length.

### withBreakIterator

public UnifiedHighlighter.Builder withBreakIterator(Supplier<BreakIterator> value)

### withFieldMatcher

public UnifiedHighlighter.Builder withFieldMatcher(Predicate<String> value)

### withMaskedFieldsFunc

public UnifiedHighlighter.Builder withMaskedFieldsFunc(Function<String,Set<String>> maskedFieldsFunc)
Set up a function that given a field retuns a set of masked fields whose matches are combined to highlight the given field. Masked fields should not include the original field. This is useful when you want to highlight a field based on matches from several fields.

Note: All masked fields must share the same source as the field being highlighted, otherwise their offsets will not correspond to the highlighted field.

Note: Only the field being highlighted must provide an original source value (e.g. through stored field), other masked fields don't need it.

### withScorer

public UnifiedHighlighter.Builder withScorer(PassageScorer value)

### withFormatter

public UnifiedHighlighter.Builder withFormatter(PassageFormatter value)

### withMaxNoHighlightPassages

public UnifiedHighlighter.Builder withMaxNoHighlightPassages(int value)

### withCacheFieldValCharsThreshold

public UnifiedHighlighter.Builder withCacheFieldValCharsThreshold(int value)

### withPassageSortComparator

public UnifiedHighlighter.Builder withPassageSortComparator(Comparator<Passage> value)

### build

public UnifiedHighlighter build()

### getIndexSearcher

public IndexSearcher getIndexSearcher()
... as passed in from the Builder constructor.

### getIndexAnalyzer

public Analyzer getIndexAnalyzer()
... as passed in from the Builder constructor.

### getFlags

public Set<UnifiedHighlighter.HighlightFlag> getFlags()