Class AbstractExcerpt
- java.lang.Object
-
- org.apache.jackrabbit.core.query.lucene.AbstractExcerpt
-
- All Implemented Interfaces:
ExcerptProvider
,HighlightingExcerptProvider
- Direct Known Subclasses:
DefaultHTMLExcerpt
,DefaultXMLExcerpt
,WeightedHTMLExcerpt
,WeightedXMLExcerpt
public abstract class AbstractExcerpt extends Object implements HighlightingExcerptProvider
AbstractExcerpt
implements base functionality for an excerpt provider.
-
-
Field Summary
Fields Modifier and Type Field Description protected SearchIndex
index
The search index.protected Query
query
The current query.-
Fields inherited from interface org.apache.jackrabbit.core.query.lucene.ExcerptProvider
REP_EXCERPT
-
-
Constructor Summary
Constructors Constructor Description AbstractExcerpt()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String
createExcerpt(TermPositionVector tpv, String text, int maxFragments, int maxFragmentSize)
Creates an excerpt for the giventext
using token offset information provided bytpv
.String
getExcerpt(NodeId id, int maxFragments, int maxFragmentSize)
Returns the XML excerpt for the node withid
.protected Set<Term[]>
getQueryTerms()
String
highlight(String text)
Highlights the matching terms in the passedtext
.void
init(Query query, SearchIndex index)
Initializes this excerpt provider.
-
-
-
Field Detail
-
index
protected SearchIndex index
The search index.
-
query
protected Query query
The current query.
-
-
Method Detail
-
init
public void init(Query query, SearchIndex index) throws IOException
Initializes this excerpt provider.- Specified by:
init
in interfaceExcerptProvider
- Parameters:
query
- excerpts will be based on this query.index
- provides access to the search index.- Throws:
IOException
- if an error occurs while initializing this excerpt provider.
-
getExcerpt
public String getExcerpt(NodeId id, int maxFragments, int maxFragmentSize) throws IOException
Returns the XML excerpt for the node withid
.- Specified by:
getExcerpt
in interfaceExcerptProvider
- Parameters:
id
- a node id.maxFragments
- the maximum number of fragments to create.maxFragmentSize
- the maximum number of characters in a fragment.- Returns:
- the XML excerpt or
null
if there is no node withid
. - Throws:
IOException
- if an error occurs while creating the excerpt.
-
highlight
public String highlight(String text) throws IOException
Highlights the matching terms in the passedtext
.- Specified by:
highlight
in interfaceHighlightingExcerptProvider
- Parameters:
text
- the input text.- Returns:
- the highlighted text.
- Throws:
IOException
- if an error occurs while highlighting the text.
-
createExcerpt
protected abstract String createExcerpt(TermPositionVector tpv, String text, int maxFragments, int maxFragmentSize) throws IOException
Creates an excerpt for the giventext
using token offset information provided bytpv
.- Parameters:
tpv
- the term position vector for the fulltext field.text
- the original text.maxFragments
- the maximum number of fragments to create.maxFragmentSize
- the maximum number of characters in a fragment.- Returns:
- the xml excerpt.
- Throws:
IOException
- if an error occurs while creating the excerpt.
-
-