org.compass.core.impl
Class DefaultCompassHighlighter

java.lang.Object
  extended by org.compass.core.impl.DefaultCompassHighlighter
All Implemented Interfaces:
CompassHighlighter

public class DefaultCompassHighlighter
extends Object
implements CompassHighlighter

Author:
kimchy

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.compass.core.CompassHighlighter
CompassHighlighter.TextTokenizer
 
Constructor Summary
DefaultCompassHighlighter(InternalCompassSession session, InternalCompassHits hits, int n)
           
 
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 CompassHighlighter.fragmentsWithSeparator(String).
 CompassHighlighter setTextTokenizer(CompassHighlighter.TextTokenizer textTokenizer)
          Sets how the text will be tokenized for highlighting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCompassHighlighter

public DefaultCompassHighlighter(InternalCompassSession session,
                                 InternalCompassHits hits,
                                 int n)
Method Detail

setAnalyzer

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

Specified by:
setAnalyzer in interface CompassHighlighter
Parameters:
analyzerName - The analyzer name that will be used.
Returns:
the highlighter
Throws:
CompassException

setAnalyzer

public CompassHighlighter setAnalyzer(Resource resource)
                               throws CompassException
Description copied from interface: CompassHighlighter
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).

Specified by:
setAnalyzer in interface CompassHighlighter
Parameters:
resource - The resource to derive the analyzer from
Returns:
the highlighter
Throws:
CompassException

setHighlighter

public CompassHighlighter setHighlighter(String highlighterName)
                                  throws CompassException
Description copied from interface: CompassHighlighter
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.

Specified by:
setHighlighter in interface CompassHighlighter
Parameters:
highlighterName - The name of the highlighter that will be used
Returns:
the higlighter
Throws:
CompassException

setSeparator

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

Specified by:
setSeparator in interface CompassHighlighter
Parameters:
separator - The separator used
Returns:
the highlighter
Throws:
CompassException

setMaxNumFragments

public CompassHighlighter setMaxNumFragments(int maxNumFragments)
                                      throws CompassException
Description copied from interface: CompassHighlighter
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.

Specified by:
setMaxNumFragments in interface CompassHighlighter
Parameters:
maxNumFragments - The maximum number if fragments
Returns:
the highlighter
Throws:
CompassException

setMaxBytesToAnalyze

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

Specified by:
setMaxBytesToAnalyze in interface CompassHighlighter
Parameters:
maxBytesToAnalyze - The maximum number of bytes analyzed for highlighting
Returns:
the highlighter
Throws:
CompassException

setTextTokenizer

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

Specified by:
setTextTokenizer in interface CompassHighlighter
Parameters:
textTokenizer - How the text will be tokenized for highlighting
Returns:
the highlighter
Throws:
CompassException

fragment

public String fragment(String propertyName)
                throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
fragment in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragment text highlighted.
Throws:
CompassException

fragment

public String fragment(String propertyName,
                       String text)
                throws CompassException
Description copied from interface: CompassHighlighter
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)

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

fragments

public String[] fragments(String propertyName)
                   throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
fragments in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted.
Throws:
CompassException

fragments

public String[] fragments(String propertyName,
                          String text)
                   throws CompassException
Description copied from interface: CompassHighlighter
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)

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

fragmentsWithSeparator

public String fragmentsWithSeparator(String propertyName)
                              throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
fragmentsWithSeparator in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

fragmentsWithSeparator

public String fragmentsWithSeparator(String propertyName,
                                     String text)
                              throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
fragmentsWithSeparator in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
text - The text to be highlighted.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

multiValueFragment

public String[] multiValueFragment(String propertyName)
                            throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
multiValueFragment in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragment texts highlighted.
Throws:
CompassException

multiValueFragment

public String[] multiValueFragment(String propertyName,
                                   String[] texts)
                            throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
multiValueFragment in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
texts - Texts to be highlighted.
Returns:
The best fragment texts highlighted.
Throws:
CompassException

multiValueFragmentWithSeparator

public String multiValueFragmentWithSeparator(String propertyName)
                                       throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
multiValueFragmentWithSeparator in interface CompassHighlighter
Parameters:
propertyName - The resource property name / meta-data.
Returns:
The best fragments highlighted and separated.
Throws:
CompassException

multiValueFragmentWithSeparator

public String multiValueFragmentWithSeparator(String propertyName,
                                              String[] texts)
                                       throws CompassException
Description copied from interface: CompassHighlighter
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)

Specified by:
multiValueFragmentWithSeparator in interface CompassHighlighter
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-2009 The Compass Project.