Class DefaultHighlighter
- java.lang.Object
-
- org.apache.jackrabbit.core.query.lucene.DefaultHighlighter
-
- Direct Known Subclasses:
WeightedHighlighter
public class DefaultHighlighter extends Object
This is an adapted version of theFulltextHighlighterposted in issue: LUCENE-644.Important: for this highlighter to function properly, field must be stored with token offsets.
Use Field constructorField(String, String, Field.Store, Field.Index, Field.TermVector)where the last argument is eitherField.TermVector.WITH_POSITIONS_OFFSETSorField.TermVector.WITH_OFFSETS- See Also:
TermPositionVector,TermFreqVector
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAXFRAGMENTSA default value of3static intDEFAULT_SURROUNDA default value of75static StringEND_EXCERPTstatic StringEND_FRAGMENT_SEPARATORstatic StringEND_HIGHLIGHTstatic StringSTART_EXCERPTstatic StringSTART_FRAGMENT_SEPARATORstatic StringSTART_HIGHLIGHT
-
Constructor Summary
Constructors Modifier Constructor Description protectedDefaultHighlighter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringcreateDefaultExcerpt(String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, int maxLength)Creates a default excerpt with the given text.protected StringdoHighlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround)protected Stringescape(String input)Escapes input text suitable for the output format.static Stringhighlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, int maxFragments, int surround)static Stringhighlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround)protected StringmergeFragments(TermVectorOffsetInfo[] offsets, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround)
-
-
-
Field Detail
-
DEFAULT_MAXFRAGMENTS
public static final int DEFAULT_MAXFRAGMENTS
A default value of3- See Also:
- Constant Field Values
-
DEFAULT_SURROUND
public static final int DEFAULT_SURROUND
A default value of75- See Also:
- Constant Field Values
-
START_EXCERPT
public static final String START_EXCERPT
- See Also:
- Constant Field Values
-
END_EXCERPT
public static final String END_EXCERPT
- See Also:
- Constant Field Values
-
START_FRAGMENT_SEPARATOR
public static final String START_FRAGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
END_FRAGMENT_SEPARATOR
public static final String END_FRAGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
START_HIGHLIGHT
public static final String START_HIGHLIGHT
- See Also:
- Constant Field Values
-
END_HIGHLIGHT
public static final String END_HIGHLIGHT
- See Also:
- Constant Field Values
-
-
Method Detail
-
highlight
public static String highlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
- Parameters:
tvec- the term position vector for this hitqueryTerms- the query terms.text- the original text that was used to create the tokens.excerptStart- this string is prepended to the excerptexcerptEnd- this string is appended to the excerptfragmentStart- this string is prepended to every fragmentfragmentEnd- this string is appended to the end of every fragement.hlStart- the string used to prepend a highlighted token, for example"<b>"hlEnd- the string used to append a highlighted token, for example"</b>"maxFragments- the maximum number of fragmentssurround- the maximum number of chars surrounding a highlighted token- Returns:
- a String with text fragments where tokens from the query are highlighted
- Throws:
IOException
-
highlight
public static String highlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, int maxFragments, int surround) throws IOException
- Parameters:
tvec- the term position vector for this hitqueryTerms- the query terms.text- the original text that was used to create the tokens.maxFragments- the maximum number of fragmentssurround- the maximum number of chars surrounding a highlighted token- Returns:
- a String with text fragments where tokens from the query are highlighted
- Throws:
IOException
-
doHighlight
protected String doHighlight(TermPositionVector tvec, Set<Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
-
mergeFragments
protected String mergeFragments(TermVectorOffsetInfo[] offsets, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
- Throws:
IOException
-
createDefaultExcerpt
protected String createDefaultExcerpt(String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, int maxLength) throws IOException
Creates a default excerpt with the given text.- Parameters:
text- the text.excerptStart- the excerpt start.excerptEnd- the excerpt end.fragmentStart- the fragment start.fragmentEnd- the fragment end.maxLength- the maximum length of the fragment.- Returns:
- a default excerpt.
- Throws:
IOException- if an error occurs while reading from the text.
-
-