Copyright© 2008-2023 Sitevision AB, all rights reserved.
@Requireable(value="SearcherBuilder") public interface SearcherBuilder extends Builder<Searcher>
Builder for creating a Searcher
with a specific setup of components.
The following components can be set. All components are optional.
Parser
- what parser should be used to handle the queries and what field/fields should be queried?
Default: a default multi-field parser.
Filter
- how should the result be limited?
Default: null
(i.e. no filtering).
SpellCheck
- should the search engine try to get suggestions (did you mean)?
Default: null
(i.e. no suggestions).
Highlight
- which fields should be highlighted and how?
Default: null
(i.e. no highlighting).
Sort
- how should the result be sorted?
Default: null
(i.e. no sorting).
Monitor
- how should querying be monitored? (e.g. should search query logging mode be on or off?)
Default: null
(i.e. no monitoring).
PermissionCheck
- how should permission checks be performed? (Note! Only applicable when querying a sv:nodeIndex)
Default: null
(legacy default permission checking strategy will be used).
What index to query can also be specified. Default is the default node index (i.e. the main index with pages/images/files etc.).
Example of how to use the SearchBuilder to create a Searcher in Velocity:
## Get the search factory
#set ($searchFactory = $sitevisionUtils.searchFactory)
## Create a Filter component
#set ($filterBuilder = $searchFactory.filterBuilder)
#set ($filter = $filterBuilder.addFilterQuery('metadata.category:responsive').build())
## Create a Highlight component
#set ($highlightBuilder = $searchFactory.highlightBuilder)
#set ($highlight = $highlightBuilder.addHighlightedField('summary').build())
## Create a Sort component
#set ($lastPublishedSort = $searchFactory.getSearchSortField('lastpublished', true))
#set ($sortBuilder = $searchFactory.sortBuilder)
#set ($sort = $sortBuilder.addSortField($lastPublishedSort).build())
## Get the search builder
#set ($searcherBuilder = $searchFactory.searcherBuilder)
## Set all components and create the Searcher
#set ($searcher = $searcherBuilder.setFilter($filter).setHighlight($highlight).setSort($sort).build())
## Search and handle the result
#set ($searchResult = $searcher.search('example*', 10))
...
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.getSearcherBuilder()
.
See SearchFactory
for how to obtain an instance of the SearchFactory
interface.
Modifier and Type | Method and Description |
---|---|
Searcher |
build()
Creates a Searcher instance using currently specified components.
|
SearcherBuilder |
setFilter(Filter aFilter)
Sets the filter component.
|
SearcherBuilder |
setHighlight(Highlight aHighlight)
Sets the highlight component.
|
SearcherBuilder |
setIndex(Node anIndex)
Sets the index to search in.
|
SearcherBuilder |
setMonitor(Monitor aMonitor)
Sets the monitor component.
|
SearcherBuilder |
setParser(Parser aParser)
Sets the parser component.
|
SearcherBuilder |
setPermissionCheck(PermissionCheck aPermissionCheck)
Sets the permission check component.
|
SearcherBuilder |
setSort(Sort aSort)
Sets the sort component.
|
SearcherBuilder |
setSpellCheck(SpellCheck aSpellCheck)
Sets the spell check (suggestions/did-you-mean) component.
|
SearcherBuilder setFilter(Filter aFilter)
A Filter
instance is created via the FilterBuilder.build()
method.
aFilter
- the filter componentFilterBuilder
SearcherBuilder setHighlight(Highlight aHighlight)
A Highlight
instance is created via the HighlightBuilder.build()
method.
aHighlight
- the highlight componentHighlightBuilder
SearcherBuilder setIndex(Node anIndex) throws IllegalArgumentException
Note! If no index is set, the Searcher
that is constructed will use
the default node index (i.e. the main index with pages/images/files etc.).
Tip! Use the IndexUtil
utility to get an index.
anIndex
- the indexIllegalArgumentException
- if anIndex
isn't an index node (primary node type name should be
sv:nodeIndex
or sv:applicationIndex
)SearcherBuilder setParser(Parser aParser)
A Parser
instance is created via the ExtendedDismaxParserBuilder.build()
method
or the StandardParserBuilder.build()
method.
Note! If no Parser is set, the Searcher
that is constructed will use a default multi-field
parser (that can be constructed via ExtendedDismaxParserBuilder
).
aParser
- the parser componentExtendedDismaxParserBuilder
,
StandardParserBuilder
SearcherBuilder setSort(Sort aSort)
A Sort
instance is created via the SortBuilder.build()
method.
aSort
- the sort componentSortBuilder
SearcherBuilder setSpellCheck(SpellCheck aSpellCheck)
A SpellCheck
instance is created via the SpellCheckBuilder.build()
method.
aSpellCheck
- the spell check componentSpellCheckBuilder
SearcherBuilder setMonitor(Monitor aMonitor)
A Monitor
instance is created via the MonitorBuilder.build()
method.
aMonitor
- the monitor componentMonitorBuilder
SearcherBuilder setPermissionCheck(PermissionCheck aPermissionCheck)
Note! This component is only applicable when querying a Node index (sv:nodeIndex
)!
When querying a Custom Node index that is populated with external data, you should typically set a permission check component
that specifies the PermissionStrategy.EARLY_CHECK
strategy.
Legacy: a Searcher
without any PermissionCheck
component will use a legacy default strategy when checking
permissions. This strategy is a mix of EARLY_CHECK
and LATE_CHECK
that is kept as-is for legacy reasons only.
New search solutions with Searcher
should typically specify a PermissionCheck
component when querying
a sv:nodeIndex
.
A PermissionCheck
instance is created via the PermissionCheckBuilder.build()
method.
aPermissionCheck
- the permission check componentPermissionCheck
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-2023 Sitevision AB, all rights reserved.