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

    All Methods Instance Methods Concrete Methods
    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` | `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` | `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 Detail

    - #### 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 Detail

    - #### 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)

    - #### 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)

    - #### 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()