public final class CustomPostingsHighlighter extends XPostingsHighlighter
XPostingsHighlighter that works for a single field in a single document. It receives the field values as input and it performs discrete highlighting on each single value calling the highlightDoc method multiple times. It allows to pass in the query terms to avoid calling extract terms multiple times. The use that we make of the postings highlighter is not optimal. It would be much better to highlight multiple docs in a single call, as we actually lose its sequential IO. But that would require: 1) to make our fork more complex and harder to maintain to perform discrete highlighting (needed to return a different snippet per value when number_of_fragments=0 and the field has multiple values) 2) refactoring of the elasticsearch highlight api which currently works per hit
DEFAULT_MAX_LENGTH| Constructor and Description |
|---|
CustomPostingsHighlighter(CustomPassageFormatter
|
| Modifier and Type | Method and Description |
|---|---|
protected BreakIterator |
getBreakIterator(String
Returns the
BreakIterator to use for dividing text into passages.
|
protected int |
getContentLength(String
|
protected org |
getEmptyHighlight(String
Called to summarize a document when no hits were found.
|
protected org |
getFormatter(String
Returns the
PassageFormatter to use for formatting passages into highlighted snippets.
|
protected char |
getMultiValuedSeparator(String
Returns the logical separator between values for multi-valued fields.
|
protected int |
getOffsetForCurrentValue(String
|
Snippet |
highlightDoc(String
|
protected String |
loadCurrentFieldValue()
|
protected String |
loadFieldValues(org
Loads the String values for each field X docID to be highlighted.
|
void |
setBreakIterator(BreakIterator
|
getScorer, highlight, highlight, highlightField, highlightFields, highlightFields, highlightFields, highlightFieldsAsObjectspublic CustomPostingsHighlighter(CustomPassageFormatterpassageFormatter, List <Object > fieldValues, boolean mergeValues, int maxLength, int noMatchSize)
public Snippet[] highlightDoc(String field, org .apache .lucene .util .BytesRef [] terms, org .apache .lucene .search .IndexSearcher searcher, int docId, int maxPassages) throws IOException
IOException
protected int getContentLength(Stringfield, int docId)
protected int getOffsetForCurrentValue(Stringfield, int docId)
public void setBreakIterator(BreakIteratorbreakIterator)
protected org.apache .lucene .search .postingshighlight .PassageFormatter getFormatter(String field)
XPostingsHighlighter
PassageFormatter to use for formatting passages into highlighted snippets. This returns a new
PassageFormatter by default; subclasses can override to customize.
protected BreakIteratorgetBreakIterator(String field)
XPostingsHighlighter
BreakIterator to use for dividing text into passages. This returns
BreakIterator.getSentenceInstance(java.util.Locale) by default; subclasses can override to customize.
protected char getMultiValuedSeparator(Stringfield)
XPostingsHighlighter
U+2029 PARAGRAPH SEPARATOR (PS) if each value holds a discrete passage for highlighting.
protected org.apache .lucene .search .postingshighlight .Passage [] getEmptyHighlight(String fieldName, BreakIterator bi, int maxPassages)
XPostingsHighlighter
maxPassages sentences; subclasses can override to customize.
protected String[][] loadFieldValues(org .apache .lucene .search .IndexSearcher searcher, String [] fields, int[] docids, int maxLength) throws IOException
XPostingsHighlighter
loadFieldValues in class
XPostingsHighlighter
IOException
protected StringloadCurrentFieldValue()