MatchHighlighter.FieldValueHighlighter (Lucene 10.5.1 highlighter API)
Description: declaration: package: org.apache.lucene.search.matchhighlight, class: MatchHighlighter, interface: FieldValueHighlighter

Package org.apache.lucene.search.matchhighlight

# Interface MatchHighlighter.FieldValueHighlighter

Enclosing class:
  `MatchHighlighter`

public static interface MatchHighlighter.FieldValueHighlighter
Actual per-field highlighter. Field highlighters are probed whether they are applicable to a particular combination of (field, hasMatches) pair. If a highlighter declares it is applicable, its `format(java.lang.String, java.util.List<java.lang.String>, java.lang.String, java.util.List<org.apache.lucene.search.matchhighlight.OffsetRange>, java.util.List<org.apache.lucene.search.matchhighlight.MatchHighlighter.QueryOffsetRange>)` method is invoked and the result is returned as the field's value.

See Also:
  - `FieldValueHighlighters`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default Collection<String>`
  `alwaysFetchedFields()`
  `List<String>`
  `format(String field, List<String> values, String contiguousValue, List<OffsetRange> valueRanges, List<MatchHighlighter.QueryOffsetRange> matchOffsets)`
  Format field values into a list of final "highlights".
  `boolean`
  `isApplicable(String field, boolean hasMatches)`
  Check if this highlighter can be applied to a given field.
  `default MatchHighlighter.FieldValueHighlighter`
  `or(MatchHighlighter.FieldValueHighlighter other)`
  Returns a new field value highlighter that is a combination of this one and another one.

- ## Method Details

  - ### isApplicable

    boolean isApplicable(String field, boolean hasMatches)
    Check if this highlighter can be applied to a given field.
    Parameters:
      `field` - Field name
      `hasMatches` - `true` if the field has a non-empty set of match regions.

  - ### format

    List<String> format(String field, List<String> values, String contiguousValue, List<OffsetRange> valueRanges, List<MatchHighlighter.QueryOffsetRange> matchOffsets)
    Format field values into a list of final "highlights".

  - ### alwaysFetchedFields

    default Collection<String> alwaysFetchedFields()
    Returns:
      Returns a set of fields that must be loaded from each document, regardless of whether they had matches or not. This is useful to load and return certain fields that should always be included (identifiers, document titles, etc.).

  - ### or

    default MatchHighlighter.FieldValueHighlighter or(MatchHighlighter.FieldValueHighlighter other)
    Returns a new field value highlighter that is a combination of this one and another one.