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 hitDEFAULT_MAX_LENGTH
Constructor and Description |
---|
CustomPostingsHighlighter(CustomPassageFormatter passageFormatter,
List<Object> fieldValues,
boolean mergeValues,
int maxLength,
int noMatchSize) |
Modifier and Type | Method and Description |
---|---|
protected BreakIterator |
getBreakIterator(String field)
Returns the
BreakIterator to use for
dividing text into passages. |
protected int |
getContentLength(String field,
int docId) |
protected org.apache.lucene.search.postingshighlight.Passage[] |
getEmptyHighlight(String fieldName,
BreakIterator bi,
int maxPassages)
Called to summarize a document when no hits were
found.
|
protected org.apache.lucene.search.postingshighlight.PassageFormatter |
getFormatter(String field)
Returns the
PassageFormatter to use for
formatting passages into highlighted snippets. |
protected char |
getMultiValuedSeparator(String field)
Returns the logical separator between values for multi-valued fields.
|
protected int |
getOffsetForCurrentValue(String field,
int docId) |
Snippet[] |
highlightDoc(String field,
org.apache.lucene.util.BytesRef[] terms,
org.apache.lucene.search.IndexSearcher searcher,
int docId,
int maxPassages) |
protected String |
loadCurrentFieldValue() |
protected String[][] |
loadFieldValues(org.apache.lucene.search.IndexSearcher searcher,
String[] fields,
int[] docids,
int maxLength)
Loads the String values for each field X docID to be
highlighted.
|
void |
setBreakIterator(BreakIterator breakIterator) |
getScorer, highlight, highlight, highlightField, highlightFields, highlightFields, highlightFields, highlightFieldsAsObjects
public CustomPostingsHighlighter(CustomPassageFormatter passageFormatter, 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(String field, int docId)
getContentLength
in class XPostingsHighlighter
protected int getOffsetForCurrentValue(String field, int docId)
getOffsetForCurrentValue
in class XPostingsHighlighter
public void setBreakIterator(BreakIterator breakIterator)
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.getFormatter
in class XPostingsHighlighter
protected BreakIterator getBreakIterator(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.getBreakIterator
in class XPostingsHighlighter
protected char getMultiValuedSeparator(String field)
XPostingsHighlighter
U+2029 PARAGRAPH SEPARATOR (PS)
if each value holds a discrete passage for highlighting.getMultiValuedSeparator
in class XPostingsHighlighter
protected org.apache.lucene.search.postingshighlight.Passage[] getEmptyHighlight(String fieldName, BreakIterator bi, int maxPassages)
XPostingsHighlighter
maxPassages
sentences; subclasses can override
to customize.getEmptyHighlight
in class XPostingsHighlighter
protected String[][] loadFieldValues(org.apache.lucene.search.IndexSearcher searcher, String[] fields, int[] docids, int maxLength) throws IOException
XPostingsHighlighter
loadFieldValues
in class XPostingsHighlighter
IOException
protected String loadCurrentFieldValue()
Copyright © 2009–2015. All rights reserved.