Module org.elasticsearch.server
Class CustomUnifiedHighlighter
java.lang.Object
org.apache.lucene.search.uhighlight.UnifiedHighlighter
org.elasticsearch.lucene.search.uhighlight.CustomUnifiedHighlighter
public final class CustomUnifiedHighlighter
extends org.apache.lucene.search.uhighlight.UnifiedHighlighter
Subclass of the
UnifiedHighlighter
that works for a single field in a single document.
Uses a custom PassageFormatter
. Accepts field content as a constructor
argument, given that loadings field value can be done reading from _source field.
Supports using different BreakIterator
to break the text into fragments. Considers every distinct field
value as a discrete passage for highlighting (unless the whole content needs to be highlighted).
Supports both returning empty snippets and non highlighted snippets when no highlighting can be performed.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.search.uhighlight.UnifiedHighlighter
org.apache.lucene.search.uhighlight.UnifiedHighlighter.Builder, org.apache.lucene.search.uhighlight.UnifiedHighlighter.HighlightFlag, org.apache.lucene.search.uhighlight.UnifiedHighlighter.LimitedStoredFieldVisitor, org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource
-
Field Summary
Fields inherited from class org.apache.lucene.search.uhighlight.UnifiedHighlighter
DEFAULT_CACHE_CHARS_THRESHOLD, DEFAULT_MAX_LENGTH, fieldInfos, indexAnalyzer, searcher, ZERO_LEN_AUTOMATA_ARRAY
-
Constructor Summary
ConstructorDescriptionCustomUnifiedHighlighter
(org.apache.lucene.search.uhighlight.UnifiedHighlighter.Builder builder, org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource offsetSource, Locale breakIteratorLocale, String index, String field, org.apache.lucene.search.Query query, int noMatchSize, int maxPassages, int maxAnalyzedOffset, Integer queryMaxAnalyzedOffset, boolean requireFieldMatch, boolean weightMatchesEnabled) Creates a new instance ofCustomUnifiedHighlighter
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.lucene.search.uhighlight.PassageFormatter
protected org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource
getOffsetSource
(String field) Forces the offset source for this highlighterSnippet[]
highlightField
(org.apache.lucene.index.LeafReader reader, int docId, CheckedSupplier<String, IOException> loadFieldValue) Highlights the field value.protected org.apache.lucene.search.uhighlight.FieldHighlighter
newFieldHighlighter
(String field, org.apache.lucene.search.uhighlight.FieldOffsetStrategy fieldOffsetStrategy, BreakIterator breakIterator, org.apache.lucene.search.uhighlight.PassageScorer passageScorer, int maxPassages, int maxNoHighlightPassages, org.apache.lucene.search.uhighlight.PassageFormatter passageFormatter) protected Collection<org.apache.lucene.search.Query>
preSpanQueryRewrite
(org.apache.lucene.search.Query query) Methods inherited from class org.apache.lucene.search.uhighlight.UnifiedHighlighter
builder, builderWithoutSearcher, evaluateFlags, evaluateFlags, evaluateFlags, extractTerms, filterExtractedTerms, getAutomata, getBreakIterator, getCacheFieldValCharsThreshold, getFieldHighlighter, getFieldInfo, getFieldMatcher, getFlags, getFormatter, getHighlightComponents, getIndexAnalyzer, getIndexSearcher, getMaxLength, getMaxNoHighlightPassages, getOffsetStrategy, getOptimizedOffsetSource, getPhraseHelper, getScorer, hasUnrecognizedQuery, highlight, highlight, highlightFields, highlightFields, highlightFields, highlightFieldsAsObjects, highlightWithoutSearcher, loadFieldValues, newLimitedStoredFieldsVisitor, requiresRewrite, setBreakIterator, setCacheFieldValCharsThreshold, setFieldMatcher, setFormatter, setHandleMultiTermQuery, setHighlightPhrasesStrictly, setMaxLength, setMaxNoHighlightPassages, setPassageRelevancyOverSpeed, setScorer, setWeightMatches, shouldHandleMultiTermQuery, shouldHighlightPhrasesStrictly, shouldPreferPassageRelevancyOverSpeed
-
Field Details
-
MULTIVAL_SEP_CHAR
public static final char MULTIVAL_SEP_CHAR- See Also:
-
-
Constructor Details
-
CustomUnifiedHighlighter
public CustomUnifiedHighlighter(org.apache.lucene.search.uhighlight.UnifiedHighlighter.Builder builder, org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource offsetSource, @Nullable Locale breakIteratorLocale, String index, String field, org.apache.lucene.search.Query query, int noMatchSize, int maxPassages, int maxAnalyzedOffset, Integer queryMaxAnalyzedOffset, boolean requireFieldMatch, boolean weightMatchesEnabled) Creates a new instance ofCustomUnifiedHighlighter
- Parameters:
builder
- theUnifiedHighlighter.Builder
for the underlying highlighter.offsetSource
- theUnifiedHighlighter.OffsetSource
to used for offsets retrieval.breakIteratorLocale
- theLocale
to use for dividing text into passages. If nullLocale.ROOT
is used.index
- the index we're highlighting, mostly used for error messagesfield
- the name of the field we're highlightingquery
- the query we're highlightingnoMatchSize
- The size of the text that should be returned when no highlighting can be performed.maxPassages
- the maximum number of passes to highlightmaxAnalyzedOffset
- if the field is more than this long we'll refuse to use the ANALYZED offset source for it because it'd be super slowweightMatchesEnabled
- whether theUnifiedHighlighter.HighlightFlag.WEIGHT_MATCHES
should be enabled
-
-
Method Details
-
highlightField
public Snippet[] highlightField(org.apache.lucene.index.LeafReader reader, int docId, CheckedSupplier<String, IOException> loadFieldValue) throws IOExceptionHighlights the field value.- Throws:
IOException
-
getFormatter
public org.apache.lucene.search.uhighlight.PassageFormatter getFormatter() -
newFieldHighlighter
protected org.apache.lucene.search.uhighlight.FieldHighlighter newFieldHighlighter(String field, org.apache.lucene.search.uhighlight.FieldOffsetStrategy fieldOffsetStrategy, BreakIterator breakIterator, org.apache.lucene.search.uhighlight.PassageScorer passageScorer, int maxPassages, int maxNoHighlightPassages, org.apache.lucene.search.uhighlight.PassageFormatter passageFormatter) - Overrides:
newFieldHighlighter
in classorg.apache.lucene.search.uhighlight.UnifiedHighlighter
-
preSpanQueryRewrite
protected Collection<org.apache.lucene.search.Query> preSpanQueryRewrite(org.apache.lucene.search.Query query) - Overrides:
preSpanQueryRewrite
in classorg.apache.lucene.search.uhighlight.UnifiedHighlighter
-
getOffsetSource
protected org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource getOffsetSource(String field) Forces the offset source for this highlighter- Overrides:
getOffsetSource
in classorg.apache.lucene.search.uhighlight.UnifiedHighlighter
-