public class CustomUnifiedHighlighter
extends org.apache.lucene.search.uhighlight.UnifiedHighlighter
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.org.apache.lucene.search.uhighlight.UnifiedHighlighter.HighlightFlag, org.apache.lucene.search.uhighlight.UnifiedHighlighter.LimitedStoredFieldVisitor, org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource
Modifier and Type | Field | Description |
---|---|---|
static char |
MULTIVAL_SEP_CHAR |
Constructor | Description |
---|---|
CustomUnifiedHighlighter(org.apache.lucene.search.IndexSearcher searcher,
org.apache.lucene.analysis.Analyzer analyzer,
org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource offsetSource,
org.apache.lucene.search.uhighlight.PassageFormatter passageFormatter,
java.util.Locale breakIteratorLocale,
java.text.BreakIterator breakIterator,
java.lang.String fieldValue,
int noMatchSize) |
Creates a new instance of
CustomUnifiedHighlighter |
Modifier and Type | Method | Description |
---|---|---|
protected java.text.BreakIterator |
getBreakIterator(java.lang.String field) |
|
protected org.apache.lucene.search.uhighlight.FieldHighlighter |
getFieldHighlighter(java.lang.String field,
org.apache.lucene.search.Query query,
java.util.Set<org.apache.lucene.index.Term> allTerms,
int maxPassages) |
|
protected org.apache.lucene.search.uhighlight.PassageFormatter |
getFormatter(java.lang.String field) |
|
protected org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource |
getOffsetSource(java.lang.String field) |
Forces the offset source for this highlighter
|
Snippet[] |
highlightField(java.lang.String field,
org.apache.lucene.search.Query query,
int docId,
int maxPassages) |
Highlights terms extracted from the provided query within the content of the provided field name
|
protected java.util.List<java.lang.CharSequence[]> |
loadFieldValues(java.lang.String[] fields,
org.apache.lucene.search.DocIdSetIterator docIter,
int cacheCharsThreshold) |
|
protected java.util.Collection<org.apache.lucene.search.Query> |
preMultiTermQueryRewrite(org.apache.lucene.search.Query query) |
|
protected java.util.Collection<org.apache.lucene.search.Query> |
preSpanQueryRewrite(org.apache.lucene.search.Query query) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
extractTerms, filterExtractedTerms, getAutomata, getCacheFieldValCharsThreshold, getFieldInfo, getFieldMatcher, getFlags, getIndexAnalyzer, getIndexSearcher, getMaxLength, getMaxNoHighlightPassages, getOffsetStrategy, getOptimizedOffsetSource, getPhraseHelper, getScorer, highlight, highlight, highlightFields, highlightFields, highlightFields, highlightFieldsAsObjects, highlightWithoutSearcher, newLimitedStoredFieldsVisitor, requiresRewrite, setBreakIterator, setCacheFieldValCharsThreshold, setFieldMatcher, setFormatter, setHandleMultiTermQuery, setHighlightPhrasesStrictly, setMaxLength, setMaxNoHighlightPassages, setScorer, shouldHandleMultiTermQuery, shouldHighlightPhrasesStrictly, shouldPreferPassageRelevancyOverSpeed
public static final char MULTIVAL_SEP_CHAR
public CustomUnifiedHighlighter(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource offsetSource, org.apache.lucene.search.uhighlight.PassageFormatter passageFormatter, @Nullable java.util.Locale breakIteratorLocale, @Nullable java.text.BreakIterator breakIterator, java.lang.String fieldValue, int noMatchSize)
CustomUnifiedHighlighter
analyzer
- the analyzer used for the field at index time, used for multi term queries internally.passageFormatter
- our own CustomPassageFormatter
which generates snippets in forms of Snippet
objects.offsetSource
- the UnifiedHighlighter.OffsetSource
to used for offsets retrieval.breakIteratorLocale
- the Locale
to use for dividing text into passages.
If null Locale.ROOT
is used.breakIterator
- the BreakIterator
to use for dividing text into passages.
If null BreakIterator.getSentenceInstance(Locale)
is used.fieldValue
- the original field values delimited by MULTIVAL_SEP_CHAR.noMatchSize
- The size of the text that should be returned when no highlighting can be performed.public Snippet[] highlightField(java.lang.String field, org.apache.lucene.search.Query query, int docId, int maxPassages) throws java.io.IOException
java.io.IOException
protected java.util.List<java.lang.CharSequence[]> loadFieldValues(java.lang.String[] fields, org.apache.lucene.search.DocIdSetIterator docIter, int cacheCharsThreshold) throws java.io.IOException
loadFieldValues
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
java.io.IOException
protected java.text.BreakIterator getBreakIterator(java.lang.String field)
getBreakIterator
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
protected org.apache.lucene.search.uhighlight.PassageFormatter getFormatter(java.lang.String field)
getFormatter
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
protected org.apache.lucene.search.uhighlight.FieldHighlighter getFieldHighlighter(java.lang.String field, org.apache.lucene.search.Query query, java.util.Set<org.apache.lucene.index.Term> allTerms, int maxPassages)
getFieldHighlighter
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
protected java.util.Collection<org.apache.lucene.search.Query> preMultiTermQueryRewrite(org.apache.lucene.search.Query query)
preMultiTermQueryRewrite
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
protected java.util.Collection<org.apache.lucene.search.Query> preSpanQueryRewrite(org.apache.lucene.search.Query query)
preSpanQueryRewrite
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter
protected org.apache.lucene.search.uhighlight.UnifiedHighlighter.OffsetSource getOffsetSource(java.lang.String field)
getOffsetSource
in class org.apache.lucene.search.uhighlight.UnifiedHighlighter