org.apache.jackrabbit.core.query.lucene
Class AbstractExcerpt

java.lang.Object
  extended by 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
protected  SearchIndex index
          The search index.
protected  org.apache.lucene.search.Query query
          The current query.
 
Fields inherited from interface org.apache.jackrabbit.core.query.lucene.ExcerptProvider
REP_EXCERPT
 
Constructor Summary
AbstractExcerpt()
           
 
Method Summary
protected abstract  String createExcerpt(org.apache.lucene.index.TermPositionVector tpv, String text, int maxFragments, int maxFragmentSize)
          Creates an excerpt for the given text using token offset information provided by tpv.
 String getExcerpt(NodeId id, int maxFragments, int maxFragmentSize)
          Returns the XML excerpt for the node with id.
protected  Set<org.apache.lucene.index.Term> getQueryTerms()
           
 String highlight(String text)
          Highlights the matching terms in the passed text.
 void init(org.apache.lucene.search.Query query, SearchIndex index)
          Initializes this excerpt provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

index

protected SearchIndex index
The search index.


query

protected org.apache.lucene.search.Query query
The current query.

Constructor Detail

AbstractExcerpt

public AbstractExcerpt()
Method Detail

init

public void init(org.apache.lucene.search.Query query,
                 SearchIndex index)
          throws IOException
Initializes this excerpt provider.

Specified by:
init in interface ExcerptProvider
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 with id.

Specified by:
getExcerpt in interface ExcerptProvider
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 with id.
Throws:
IOException - if an error occurs while creating the excerpt.

highlight

public String highlight(String text)
                 throws IOException
Highlights the matching terms in the passed text.

Specified by:
highlight in interface HighlightingExcerptProvider
Parameters:
text - the input text.
Returns:
the highlighted text.
Throws:
IOException - if an error occurs while highlighting the text.

createExcerpt

protected abstract String createExcerpt(org.apache.lucene.index.TermPositionVector tpv,
                                        String text,
                                        int maxFragments,
                                        int maxFragmentSize)
                                 throws IOException
Creates an excerpt for the given text using token offset information provided by tpv.

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.

getQueryTerms

protected final Set<org.apache.lucene.index.Term> getQueryTerms()
Returns:
the extracted terms from the query.


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.