Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="HighlightBuilder") public interface HighlightBuilder extends Builder<Highlight>
Builder for creating a Highlight component with specific behaviour.
HighlightBuilder has one mandatory attribute:
HighlightBuilder also has some optional attributes:
Using the HighlightBuilder is pretty straightforward, if you remember that it is stateful. Conceptually you would typically use it like this:
When you have built a Highlight instance, you can re-use the HighlightBuilder to build more instances. Typically like:
Example of how this strategy could be implemented in Velocity:
## Get the builder
#set ($searchFactory = $sitevisionUtils.searchFactory)
#set ($highlightBuilder = $searchFactory.highlightBuilder)
## Create a Highlight
#set ($summaryHighlight = $highlightBuilder.addHighlightedField('summary').build())
## Re-use the builder to create another Highlight
#set ($nameHighlight = $highlightBuilder.clearHighlightedFields().addHighlightedField('name').build())
Tip! The Builder interface documentation contains
more information about Builders and how to work with them!
An instance of the Sitevision class implementing this interface can be obtained via
SearchFactory.getHighlightBuilder().
See SearchFactory for how to obtain an instance of the SearchFactory interface.
| Modifier and Type | Method and Description |
|---|---|
HighlightBuilder |
addHighlightedField(String aHighlightedField)
Adds a field that should be highlighted.
|
Highlight |
build()
Creates a Highlight component instance using currently specified state/behaviour.
|
HighlightBuilder |
clearHighlightedFields()
Removes all previously added highlighted fields.
|
HighlightBuilder |
setFragmentCharCount(int aCharCount)
Sets the number of chars that highlighted fragment should contain.
|
HighlightBuilder |
setFragmentPostString(String aPostString)
Sets the end value for the highlighted section(s) of a fragment.
|
HighlightBuilder |
setFragmentPreString(String aPreString)
Sets the start value for the highlighted section(s) of a fragment.
|
HighlightBuilder addHighlightedField(String aHighlightedField)
Solr note: this is the 'hl.fl' param
aHighlightedField - name of the field, a null or whitespace-only value will be ignoredHighlightBuilder clearHighlightedFields()
HighlightBuilder setFragmentCharCount(int aCharCount) throws IllegalArgumentException
If no char count is specified, the default value of the index config will be used (200).
Solr note: this is the 'hl.fragsize' param
aCharCount - the char countIllegalArgumentException - if aCharCount is zero or negativeHighlightBuilder setFragmentPreString(String aPreString)
If the pre string and post string are not specified, the default value of the index config will be used ('<mark>' and '</mark>').
Solr note: this is the 'hl.simple.pre' param
aPreString - a fragment startHighlightBuilder setFragmentPostString(String aPostString)
Note! The fragment pre value must match the fragment post string! E.g: if the pre string is "<em>", the post string would typically be "</em>".
Solr note: this is the 'hl.simple.post' param
aPostString - a fragment endHighlight build() throws IllegalStateException
build in interface Builder<Highlight>IllegalStateException - if no highlighted field is specified, or if pre and post strings doesn't match (e.g. one of them is null)Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.