public class Highlighter
extends java.lang.Object
Fragmenter
, Scorer
, Formatter
,
Encoder
and tokenizers.
This is Lucene's original Highlighter; there are others.Modifier and Type | Class and Description |
---|---|
(package private) static class |
Highlighter.FragmentQueue |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CHARS_TO_ANALYZE |
private Encoder |
encoder |
private Formatter |
formatter |
private Scorer |
fragmentScorer |
private int |
maxDocCharsToAnalyze |
private Fragmenter |
textFragmenter |
Constructor and Description |
---|
Highlighter(Formatter formatter,
Encoder encoder,
Scorer fragmentScorer) |
Highlighter(Formatter formatter,
Scorer fragmentScorer) |
Highlighter(Scorer fragmentScorer) |
Modifier and Type | Method and Description |
---|---|
private static void |
ensureArgumentNotNull(java.lang.Object argument,
java.lang.String message)
Throws an IllegalArgumentException with the provided message if 'argument' is null.
|
java.lang.String |
getBestFragment(Analyzer analyzer,
java.lang.String fieldName,
java.lang.String text)
Highlights chosen terms in a text, extracting the most relevant section.
|
java.lang.String |
getBestFragment(TokenStream tokenStream,
java.lang.String text)
Highlights chosen terms in a text, extracting the most relevant section.
|
java.lang.String[] |
getBestFragments(Analyzer analyzer,
java.lang.String fieldName,
java.lang.String text,
int maxNumFragments)
Highlights chosen terms in a text, extracting the most relevant sections.
|
java.lang.String[] |
getBestFragments(TokenStream tokenStream,
java.lang.String text,
int maxNumFragments)
Highlights chosen terms in a text, extracting the most relevant sections.
|
java.lang.String |
getBestFragments(TokenStream tokenStream,
java.lang.String text,
int maxNumFragments,
java.lang.String separator)
Highlights terms in the text , extracting the most relevant sections
and concatenating the chosen fragments with a separator (typically "...").
|
TextFragment[] |
getBestTextFragments(TokenStream tokenStream,
java.lang.String text,
boolean mergeContiguousFragments,
int maxNumFragments)
Low level api to get the most relevant (formatted) sections of the document.
|
Encoder |
getEncoder() |
Scorer |
getFragmentScorer() |
int |
getMaxDocCharsToAnalyze() |
Fragmenter |
getTextFragmenter() |
private void |
mergeContiguousFragments(TextFragment[] frag)
Improves readability of a score-sorted list of TextFragments by merging any fragments
that were contiguous in the original text into one larger fragment with the correct order.
|
void |
setEncoder(Encoder encoder) |
void |
setFragmentScorer(Scorer scorer) |
void |
setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze) |
void |
setTextFragmenter(Fragmenter fragmenter) |
public static final int DEFAULT_MAX_CHARS_TO_ANALYZE
private Formatter formatter
private Encoder encoder
private Scorer fragmentScorer
private int maxDocCharsToAnalyze
private Fragmenter textFragmenter
public Highlighter(Scorer fragmentScorer)
public final java.lang.String getBestFragment(Analyzer analyzer, java.lang.String fieldName, java.lang.String text) throws java.io.IOException, InvalidTokenOffsetsException
getBestFragment(TokenStream, String)
analyzer
- the analyzer that will be used to split text
into chunkstext
- text to highlight terms infieldName
- Name of field used to influence analyzer's tokenization policyInvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthjava.io.IOException
public final java.lang.String getBestFragment(TokenStream tokenStream, java.lang.String text) throws java.io.IOException, InvalidTokenOffsetsException
tokenStream
- a stream of tokens identified in the text parameter, including offset information.
This is typically produced by an analyzer re-parsing a document's
text. Some work may be done on retrieving TokenStreams more efficiently
by adding support for storing original text position data in the Lucene
index but this support is not currently available (as of Lucene 1.4 rc2).text
- text to highlight terms inInvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthjava.io.IOException
public final java.lang.String[] getBestFragments(Analyzer analyzer, java.lang.String fieldName, java.lang.String text, int maxNumFragments) throws java.io.IOException, InvalidTokenOffsetsException
getBestFragments(TokenStream, String, int)
analyzer
- the analyzer that will be used to split text
into chunksfieldName
- the name of the field being highlighted (used by analyzer)text
- text to highlight terms inmaxNumFragments
- the maximum number of fragments.InvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthjava.io.IOException
public final java.lang.String[] getBestFragments(TokenStream tokenStream, java.lang.String text, int maxNumFragments) throws java.io.IOException, InvalidTokenOffsetsException
text
- text to highlight terms inmaxNumFragments
- the maximum number of fragments.InvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthjava.io.IOException
public final TextFragment[] getBestTextFragments(TokenStream tokenStream, java.lang.String text, boolean mergeContiguousFragments, int maxNumFragments) throws java.io.IOException, InvalidTokenOffsetsException
java.io.IOException
- If there is a low-level I/O errorInvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthprivate void mergeContiguousFragments(TextFragment[] frag)
frag
- An array of document fragments in descending scorepublic final java.lang.String getBestFragments(TokenStream tokenStream, java.lang.String text, int maxNumFragments, java.lang.String separator) throws java.io.IOException, InvalidTokenOffsetsException
text
- text to highlight terms inmaxNumFragments
- the maximum number of fragments.separator
- the separator used to intersperse the document fragments (typically "...")InvalidTokenOffsetsException
- thrown if any token's endOffset exceeds the provided text's lengthjava.io.IOException
public int getMaxDocCharsToAnalyze()
public void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
public Fragmenter getTextFragmenter()
public void setTextFragmenter(Fragmenter fragmenter)
public Scorer getFragmentScorer()
public void setFragmentScorer(Scorer scorer)
public Encoder getEncoder()
public void setEncoder(Encoder encoder)
private static void ensureArgumentNotNull(java.lang.Object argument, java.lang.String message)
argument
- the argument to be null-checkedmessage
- the message of the exception thrown if argument == null