org.compass.core
Interface CompassHighlighter

All Known Implementing Classes:
DefaultCompassHighlighter

public interface CompassHighlighter

A highlighter tool that can highlight hits in a given text based on an executed query.

Author:
kimchy
See Also:
CompassHits.highlighter(int)

Nested Class Summary
static class CompassHighlighter.TextTokenizer
          Controls the way text will be tokenized in order to perform the highlight operation.
 
Method Summary
 String fragment(String propertyName)
          Returns the best highlighted fragment for the given property name / meta-data.
 String fragment(String propertyName, String text)
          Returns the best highlighted fragment for the given property name / meta-data.
 String[] fragments(String propertyName)
          Returns the best highlighted fragments for the given property name / meta-data.
 String[] fragments(String propertyName, String text)
          Returns the best highlighted fragments for the given property name / meta-data.
 String fragmentsWithSeparator(String propertyName)
          Returns the best highlighted fragments for the given property name / meta-data, separated with the given separator.
 String fragmentsWithSeparator(String propertyName, String text)
          Returns the best highlighted fragments for the given property name / meta-data, separated with the given separator.
 String[] multiValueFragment(String propertyName)
          Returns the best highlighted fragment of each matching multi resource property name / meta-data (i.e.: when there is more then one property of the same name).
 String[] multiValueFragment(String propertyName, String[] texts)
          Returns the best highlighted fragment of each matching multi resource property name / meta-data (i.e.: when there is more then one property of the same name).
 String multiValueFragmentWithSeparator(String propertyName)
          Returns the best highlighted fragments for the given multi property name / meta-data, separated with the given separator.
 String multiValueFragmentWithSeparator(String propertyName, String[] texts)
          Returns the best highlighted fragments for the given multi property name / meta-data, separated with the given separator.
 CompassHighlighter setAnalyzer(Resource resource)
          Sets the analyzer that will be used if analysis of the text is needed (see CompassHighlighter.TextTokenizer).
 CompassHighlighter setAnalyzer(String analyzerName)
          Sets the analyzer that will be used if analysis of the text is needed (see CompassHighlighter.TextTokenizer).
 CompassHighlighter setHighlighter(String highlighterName)
          Sets the highlighter that will be used out the ones set in the configuration.
 CompassHighlighter setMaxBytesToAnalyze(int maxBytesToAnalyze)
          Sets the maximum number of bytes that will be analyzed for highlighting.
 CompassHighlighter setMaxNumFragments(int maxNumFragments)
          Sets the maximum number of fragments that can be returned or combined to a separator.
 CompassHighlighter setSeparator(String separator)
          Sets the separator string that will be used to combine different fragments in fragmentsWithSeparator(String).
 CompassHighlighter setTextTokenizer(CompassHighlighter.TextTokenizer textTokenizer)
          Sets how the text will be tokenized for highlighting.
 

Method Detail

setHighlighter

CompassHighlighter setHighlighter(String highlighterName)
                                  throws CompassException
Sets the highlighter that will be used out the ones set in the configuration. The highlighters are groups of pre-set configurations for the sepcified highlighter. The default one is called default.

Parameters:
highlighterName - The name of the highlighter that will be used
Returns:
the higlighter
Throws:
CompassException

setAnalyzer

CompassHighlighter setAnalyzer(String analyzerName)
                               throws CompassException
Sets the analyzer that will be used if analysis of the text is needed (see CompassHighlighter.TextTokenizer).

Parameters:
analyzerName - The analyzer name that will be used.
Returns:
the highlighter
Throws:
CompassException

setAnalyzer

CompassHighlighter setAnalyzer(Resource resource)
                               throws CompassException
Sets the analyzer that will be used if analysis of the text is needed (see CompassHighlighter.TextTokenizer). Uses the resource to derive the analyzer that will be used (works also with per resource property analyzer).

Parameters:
resource - The resource to derive the analyzer from
Returns:
the highlighter
Throws:
CompassException

setSeparator

CompassHighlighter setSeparator(String separator)
                                throws CompassException
Sets the separator string that will be used to combine different fragments in fragmentsWithSeparator(String). If not set, will use the separator configured for the chosen highlighter.

Parameters:
separator - The separator used
Returns:
the highlighter
Throws:
CompassException

setMaxBytesToAnalyze

CompassHighlighter setMaxBytesToAnalyze(int maxBytesToAnalyze)
                                        throws CompassException
Sets the maximum number of bytes that will be analyzed for highlighting. If not set, will use the value configured for the chosen highlighter.

Parameters:
maxBytesToAnalyze - The maximum number of bytes analyzed for highlighting
Returns:
the highlighter
Throws:
CompassException

setMaxNumFragments

CompassHighlighter setMaxNumFragments(int maxNumFragments)
                                      throws CompassException
Sets the maximum number of fragments that can be returned or combined to a separator. If not set, will use the value configured for the chosen highlighter.

Parameters:
maxNumFragments - The maximum number if fragments
Returns:
the highlighter
Throws:
CompassException

setTextTokenizer

CompassHighlighter setTextTokenizer(CompassHighlighter.TextTokenizer textTokenizer)
                                    throws CompassException
Sets how the text will be tokenized for highlighting. If not set, will use the value configured for the chosen highlighter.

Parameters:
textTokenizer - How the text will be tokenized for highlighting
Returns:
the highlighter
Throws:
CompassException

fragment

String fragment(String propertyName)
                throws CompassException
Returns the best highlighted fragment for the given property name / meta-data. The highlighted text will be retrived from the index, so it must be stored.

Note, if there are more than one resource property name / meta-data with the same name, the text will be taken from the first one.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragment text highlighted.
Throws:
CompassException

fragment

String fragment(String propertyName,
                String text)
                throws CompassException
Returns the best highlighted fragment for the given property name / meta-data. The given text will be used for highlight. Handy when the text is not stored in the index.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
text - The text to be highlighted.
Returns:
The best fragment text highlighted.
Throws:
CompassException

fragments

String[] fragments(String propertyName)
                   throws CompassException
Returns the best highlighted fragments for the given property name / meta-data. The highlighted text will be retrived from the index, so it must be stored.

Note, that the number of fragments will be between 0 and maxNumFragments.

Note, if there are more than one resource property name / meta-data with the same name, the text will be taken from the first one.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted.
Throws:
CompassException

fragments

String[] fragments(String propertyName,
                   String text)
                   throws CompassException
Returns the best highlighted fragments for the given property name / meta-data. The given text will be used for highlight.

Note, that the number of fragments will be between 0 and maxNumFragments.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
text - The text to be highlighted.
Returns:
The best fragments highlighted.
Throws:
CompassException

fragmentsWithSeparator

String fragmentsWithSeparator(String propertyName)
                              throws CompassException
Returns the best highlighted fragments for the given property name / meta-data, separated with the given separator. The highlighted text will be retrived from the index, so it must be stored.

Note, that the number of fragments will be between 0 and maxNumFragments.

Note, if there are more than one resource property name / meta-data with the same name, the text will be taken from the first one.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

fragmentsWithSeparator

String fragmentsWithSeparator(String propertyName,
                              String text)
                              throws CompassException
Returns the best highlighted fragments for the given property name / meta-data, separated with the given separator. The given text will be used for highlight.

Note, that the number of fragments will be between 0 and maxNumFragments.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
text - The text to be highlighted.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

multiValueFragment

String[] multiValueFragment(String propertyName)
                            throws CompassException
Returns the best highlighted fragment of each matching multi resource property name / meta-data (i.e.: when there is more then one property of the same name). The highlighted texts will be retrived from the index, so it must be stored.

Note, that the number of returned fragments is not limited by maxNumFragments value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragment texts highlighted.
Throws:
CompassException

multiValueFragment

String[] multiValueFragment(String propertyName,
                            String[] texts)
                            throws CompassException
Returns the best highlighted fragment of each matching multi resource property name / meta-data (i.e.: when there is more then one property of the same name). The given texts will be used for highlight. Handy when the texts are not stored in the index.

Note, that the number of returned fragments is not limited by maxNumFragments value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
texts - Texts to be highlighted.
Returns:
The best fragment texts highlighted.
Throws:
CompassException

multiValueFragmentWithSeparator

String multiValueFragmentWithSeparator(String propertyName)
                                       throws CompassException
Returns the best highlighted fragments for the given multi property name / meta-data, separated with the given separator. The highlighted text will be retrived from the index, so it must be stored.

Note, that the number of separeted fragments is not limited by maxNumFragments value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

multiValueFragmentWithSeparator

String multiValueFragmentWithSeparator(String propertyName,
                                       String[] texts)
                                       throws CompassException
Returns the best highlighted fragments for the given multi property name / meta-data, separated with the given separator. The given texts will be used for highlight.

Note, that the number of fragments contained in returned string is not limited by maxNumFragments value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
propertyName - The resource property name / meta-data.
texts - Texts to be highlighted.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException


Copyright (c) 2004-2008 The Compass Project.