public class DefaultHighlighter extends Object
FulltextHighlighter
posted in
issue: LUCENE-644.
Important: for this highlighter to function properly, field must be stored
with token offsets.
Use Field constructor Field(String, String, Field.Store, Field.Index, Field.TermVector)
where the
last argument is either Field.TermVector#WITH_POSITIONS_OFFSETS
or
Field.TermVector.WITH_OFFSETS
TermPositionVector
,
TermFreqVector
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAXFRAGMENTS
A default value of
3 |
static int |
DEFAULT_SURROUND
A default value of
75 |
static String |
END_EXCERPT |
static String |
END_FRAGMENT_SEPARATOR |
static String |
END_HIGHLIGHT |
static String |
START_EXCERPT |
static String |
START_FRAGMENT_SEPARATOR |
static String |
START_HIGHLIGHT |
Modifier | Constructor and Description |
---|---|
protected |
DefaultHighlighter() |
Modifier and Type | Method and Description |
---|---|
protected String |
createDefaultExcerpt(String text,
String excerptStart,
String excerptEnd,
String fragmentStart,
String fragmentEnd,
int maxLength)
Creates a default excerpt with the given text.
|
protected String |
doHighlight(org.apache.lucene.index.TermPositionVector tvec,
Set<org.apache.lucene.index.Term[]> queryTerms,
String text,
String excerptStart,
String excerptEnd,
String fragmentStart,
String fragmentEnd,
String hlStart,
String hlEnd,
int maxFragments,
int surround) |
protected String |
escape(String input)
Escapes input text suitable for the output format.
|
static String |
highlight(org.apache.lucene.index.TermPositionVector tvec,
Set<org.apache.lucene.index.Term[]> queryTerms,
String text,
int maxFragments,
int surround) |
static String |
highlight(org.apache.lucene.index.TermPositionVector tvec,
Set<org.apache.lucene.index.Term[]> queryTerms,
String text,
String excerptStart,
String excerptEnd,
String fragmentStart,
String fragmentEnd,
String hlStart,
String hlEnd,
int maxFragments,
int surround) |
protected String |
mergeFragments(org.apache.lucene.index.TermVectorOffsetInfo[] offsets,
String text,
String excerptStart,
String excerptEnd,
String fragmentStart,
String fragmentEnd,
String hlStart,
String hlEnd,
int maxFragments,
int surround) |
public static final int DEFAULT_MAXFRAGMENTS
3
public static final int DEFAULT_SURROUND
75
public static final String START_EXCERPT
public static final String END_EXCERPT
public static final String START_FRAGMENT_SEPARATOR
public static final String END_FRAGMENT_SEPARATOR
public static final String START_HIGHLIGHT
public static final String END_HIGHLIGHT
public static String highlight(org.apache.lucene.index.TermPositionVector tvec, Set<org.apache.lucene.index.Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
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 tokenIOException
public static String highlight(org.apache.lucene.index.TermPositionVector tvec, Set<org.apache.lucene.index.Term[]> queryTerms, String text, int maxFragments, int surround) throws IOException
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
tokenIOException
protected String doHighlight(org.apache.lucene.index.TermPositionVector tvec, Set<org.apache.lucene.index.Term[]> queryTerms, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
protected String mergeFragments(org.apache.lucene.index.TermVectorOffsetInfo[] offsets, String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, String hlStart, String hlEnd, int maxFragments, int surround) throws IOException
IOException
protected String createDefaultExcerpt(String text, String excerptStart, String excerptEnd, String fragmentStart, String fragmentEnd, int maxLength) throws IOException
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.IOException
- if an error occurs while reading from the text.Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.