Class FastVectorHighlighter
- java.lang.Object
-
- org.apache.lucene.search.vectorhighlight.FastVectorHighlighter
-
public class FastVectorHighlighter extends Object
Another highlighter implementation.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_FIELD_MATCH
static boolean
DEFAULT_PHRASE_HIGHLIGHT
-
Constructor Summary
Constructors Constructor Description FastVectorHighlighter()
the default constructor.FastVectorHighlighter(boolean phraseHighlight, boolean fieldMatch)
a constructor.FastVectorHighlighter(boolean phraseHighlight, boolean fieldMatch, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder)
a constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getBestFragment(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize)
return the best fragment.String
getBestFragment(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder)
return the best fragment.String[]
getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, int maxNumFragments)
return the best fragments.String[]
getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, int maxNumFragments, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder)
return the best fragments.String[]
getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String storedField, Set<String> matchedFields, int fragCharSize, int maxNumFragments, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder)
Return the best fragments.FieldQuery
getFieldQuery(Query query)
create aFieldQuery
object.FieldQuery
getFieldQuery(Query query, IndexReader reader)
create aFieldQuery
object.int
getPhraseLimit()
boolean
isFieldMatch()
return whether fieldMatch or not.boolean
isPhraseHighlight()
return whether phraseHighlight or not.void
setPhraseLimit(int phraseLimit)
set the maximum number of phrases to analyze when searching for the highest-scoring phrase.
-
-
-
Field Detail
-
DEFAULT_PHRASE_HIGHLIGHT
public static final boolean DEFAULT_PHRASE_HIGHLIGHT
- See Also:
- Constant Field Values
-
DEFAULT_FIELD_MATCH
public static final boolean DEFAULT_FIELD_MATCH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FastVectorHighlighter
public FastVectorHighlighter()
the default constructor.
-
FastVectorHighlighter
public FastVectorHighlighter(boolean phraseHighlight, boolean fieldMatch)
a constructor. UsingSimpleFragListBuilder
andScoreOrderFragmentsBuilder
.- Parameters:
phraseHighlight
- true or false for phrase highlightingfieldMatch
- true of false for field matching
-
FastVectorHighlighter
public FastVectorHighlighter(boolean phraseHighlight, boolean fieldMatch, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder)
a constructor. AFragListBuilder
and aFragmentsBuilder
can be specified (plugins).- Parameters:
phraseHighlight
- true of false for phrase highlightingfieldMatch
- true of false for field matchingfragListBuilder
- an instance ofFragListBuilder
fragmentsBuilder
- an instance ofFragmentsBuilder
-
-
Method Detail
-
getFieldQuery
public FieldQuery getFieldQuery(Query query)
create aFieldQuery
object.- Parameters:
query
- a query- Returns:
- the created
FieldQuery
object
-
getFieldQuery
public FieldQuery getFieldQuery(Query query, IndexReader reader) throws IOException
create aFieldQuery
object.- Parameters:
query
- a query- Returns:
- the created
FieldQuery
object - Throws:
IOException
-
getBestFragment
public final String getBestFragment(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize) throws IOException
return the best fragment.- Parameters:
fieldQuery
-FieldQuery
objectreader
-IndexReader
of the indexdocId
- document id to be highlightedfieldName
- field of the document to be highlightedfragCharSize
- the length (number of chars) of a fragment- Returns:
- the best fragment (snippet) string
- Throws:
IOException
- If there is a low-level I/O error
-
getBestFragments
public final String[] getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, int maxNumFragments) throws IOException
return the best fragments.- Parameters:
fieldQuery
-FieldQuery
objectreader
-IndexReader
of the indexdocId
- document id to be highlightedfieldName
- field of the document to be highlightedfragCharSize
- the length (number of chars) of a fragmentmaxNumFragments
- maximum number of fragments- Returns:
- created fragments or null when no fragments created. size of the array can be less than maxNumFragments
- Throws:
IOException
- If there is a low-level I/O error
-
getBestFragment
public final String getBestFragment(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder) throws IOException
return the best fragment.- Parameters:
fieldQuery
-FieldQuery
objectreader
-IndexReader
of the indexdocId
- document id to be highlightedfieldName
- field of the document to be highlightedfragCharSize
- the length (number of chars) of a fragmentfragListBuilder
-FragListBuilder
objectfragmentsBuilder
-FragmentsBuilder
objectpreTags
- pre-tags to be used to highlight termspostTags
- post-tags to be used to highlight termsencoder
- an encoder that generates encoded text- Returns:
- the best fragment (snippet) string
- Throws:
IOException
- If there is a low-level I/O error
-
getBestFragments
public final String[] getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String fieldName, int fragCharSize, int maxNumFragments, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder) throws IOException
return the best fragments.- Parameters:
fieldQuery
-FieldQuery
objectreader
-IndexReader
of the indexdocId
- document id to be highlightedfieldName
- field of the document to be highlightedfragCharSize
- the length (number of chars) of a fragmentmaxNumFragments
- maximum number of fragmentsfragListBuilder
-FragListBuilder
objectfragmentsBuilder
-FragmentsBuilder
objectpreTags
- pre-tags to be used to highlight termspostTags
- post-tags to be used to highlight termsencoder
- an encoder that generates encoded text- Returns:
- created fragments or null when no fragments created. size of the array can be less than maxNumFragments
- Throws:
IOException
- If there is a low-level I/O error
-
getBestFragments
public final String[] getBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId, String storedField, Set<String> matchedFields, int fragCharSize, int maxNumFragments, FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder, String[] preTags, String[] postTags, Encoder encoder) throws IOException
Return the best fragments. Matches are scanned from matchedFields and turned into fragments against storedField. The highlighting may not make sense if matchedFields has matches with offsets that don't correspond features in storedField. It will outright throw aStringIndexOutOfBoundsException
if matchedFields produces offsets outside of storedField. As such it is advisable that all matchedFields share the same source as storedField or are at least a prefix of it.- Parameters:
fieldQuery
-FieldQuery
objectreader
-IndexReader
of the indexdocId
- document id to be highlightedstoredField
- field of the document that stores the textmatchedFields
- fields of the document to scan for matchesfragCharSize
- the length (number of chars) of a fragmentmaxNumFragments
- maximum number of fragmentsfragListBuilder
-FragListBuilder
objectfragmentsBuilder
-FragmentsBuilder
objectpreTags
- pre-tags to be used to highlight termspostTags
- post-tags to be used to highlight termsencoder
- an encoder that generates encoded text- Returns:
- created fragments or null when no fragments created. size of the array can be less than maxNumFragments
- Throws:
IOException
- If there is a low-level I/O error
-
isPhraseHighlight
public boolean isPhraseHighlight()
return whether phraseHighlight or not.- Returns:
- whether phraseHighlight or not
-
isFieldMatch
public boolean isFieldMatch()
return whether fieldMatch or not.- Returns:
- whether fieldMatch or not
-
getPhraseLimit
public int getPhraseLimit()
- Returns:
- the maximum number of phrases to analyze when searching for the highest-scoring phrase.
-
setPhraseLimit
public void setPhraseLimit(int phraseLimit)
set the maximum number of phrases to analyze when searching for the highest-scoring phrase. The default is unlimited (Integer.MAX_VALUE).
-
-