Interface SearchManager
- All Known Subinterfaces:
OpenSearchSearchManager
- All Known Implementing Classes:
DecoratedSearchManager
,DefaultOpenSearchSearchManager
,LuceneSearchManager
,ProfiledSearchManager
NOTE: A newer alternative which also includes write, transactional, reset and snapshot behaviour
is SearchIndexAccessor
. It also supports custom search indexes through CustomSearchIndexRegistry
or extending DelegatingSearchIndexAccessor
.
WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking.
See SiteSearchPermissionsQueryFactory
to add one yourself.
See PredefinedSearchBuilder
to build a pre-defined search which contains permission checking.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
static enum
Determines how search results will be converted into entities byconvertToEntities(SearchResults, EntityVersionPolicy)
andsearchEntities(ISearch, EntityVersionPolicy)
. -
Method Summary
Modifier and TypeMethodDescriptionconvertToEntities
(SearchResults searchResults, SearchManager.EntityVersionPolicy versionPolicy) Helper method to convert search results into a list of database entities.default String
Produce an explanation of the search query for the specified contentId.long
scan
(EnumSet<SearchIndex> indexes, SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String, String[]>> consumer) ExecuteConsumer.accept(T)
for each search result.long
scan
(List<Index> indices, SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String, String[]>> consumer) ExecuteConsumer.accept(T)
for each search result.Perform a search with a given criteria.Perform a search with a given criteria, the returns searchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult.search
(SearchWithToken search) Deprecated.since 5.10.searchCategorised
(ISearch search, SearchManager.Categorizer<T> categorizer) Perform a search with the given criteria, the top results are collected per category specified by the givenSearchManager.Categorizer
.searchEntities
(ISearch search, SearchManager.EntityVersionPolicy versionPolicy) Perform a search with the given criteria, returning the results as a list of database entity objects.
-
Method Details
-
search
Perform a search with a given criteria.Will throw an InvalidSearchException if some error occurred converting the search object into a search that could be performed in the back-end. Usually this is a sign that some plugin that was used to create the search is no longer available.
If the
ISearch
contains noContentStatusQuery
in the search query or search filter tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Parameters:
search
- the search to perform- Returns:
- the results of that search
- Throws:
IllegalArgumentException
- if the search contains an invalidSearchQuery
InvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.
-
search
@Deprecated SearchResults search(SearchWithToken search) throws SearchTokenExpiredException, InvalidSearchException Deprecated.since 5.10. This method on one hand is rarely used on the other hand is not efficient to implement in ES.Perform a search against a specific version of the search index (identified by callingSearchWithToken.getSearchToken()
on the specified search).This can be useful for retrieving the next page of results after an initial search. The next page of results will be calculated from the version of the search index that the initial search was performed on.
Usage:
SearchResults searchResults = searchManager.search(search); // fetch next page of results if (!searchResults.isLastPage()) SearchResults nextPageOfSearchResults = searchManager.search(searchResults.getNextPageSearch());
If the
SearchWithToken
contains noContentStatusQuery
in the search query or search filter tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.For OpenSearch: - search token has no impact - when searchAfter is provided, it will be used to get the next page; otherwise startOffset will be used For Lucene (will be deprecated): - searchAfter will be ignored
- Parameters:
search
- a search that specifies a search token.- Returns:
- the results of that search
- Throws:
IllegalArgumentException
- if the specified search does not contain a valid search token.InvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.SearchTokenExpiredException
- if the specified search token has expired. Clients should report this the user and / or retry the search withsearch(ISearch)
.
-
search
Perform a search with a given criteria, the returns searchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult. SearchResults will throw anFieldNotRequestedException
if an attempt is made to access a field value that has not had it's key included in the projection Set.Will throw an InvalidSearchException if some error occurred converting the search object into a search that could be performed in the back-end. Usually this is a sign that some plugin that was used to create the search is no longer available.
If the
ISearch
contains noContentStatusQuery
in the search query or search filter tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Parameters:
search
-requestedFields
- requested fields. Passingnull
will request all fields, and passing empty set will request none.- Returns:
- the results of the search, containing only the requested fields.
- Throws:
InvalidSearchException
-
searchEntities
List<Searchable> searchEntities(ISearch search, SearchManager.EntityVersionPolicy versionPolicy) throws InvalidSearchException Perform a search with the given criteria, returning the results as a list of database entity objects. Unlike theconvertToEntities(SearchResults, EntityVersionPolicy)
method, the list of entities returned will not contain any nulls: search results that do not match a database record will be silently discarded.The versionPolicy determines whether the entities returned should be the same version as stored in the index (
SearchManager.EntityVersionPolicy.INDEXED_VERSION
) or the latest version of the same content (SearchManager.EntityVersionPolicy.LATEST_VERSION
). If you don't have a particular need to retrieve the latest version, it is recommended that you retrieve the indexed version so that any permission changes made to the document when updating it will be respected.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Parameters:
search
- the search to performversionPolicy
- whether to retrieve the indexed version of content found via search (recommended), or the latest version of content (not recommended)- Returns:
- a list of Searchable objects representing the search results
- Throws:
IllegalArgumentException
- if the search contains an invalidSearchQuery
InvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.- Since:
- 4.0
-
convertToEntities
List<Searchable> convertToEntities(SearchResults searchResults, SearchManager.EntityVersionPolicy versionPolicy) Helper method to convert search results into a list of database entities. Because the search index does not update at the same time as the database, a search may contain references to entities that have since been modified or deleted from the db.Entries that have been deleted from the database are removed from the returned list of entities, so the index of the entities in the returned list may not match the indexes of the search result it corresponds to.
The behaviour for entries that have been modified in the database varies based on the versionPolicy argument. If it is set to
SearchManager.EntityVersionPolicy.INDEXED_VERSION
, which is the recommended default, the returned entities will be the same version as found in the index. If it is set toSearchManager.EntityVersionPolicy.LATEST_VERSION
, the latest version of the content will be returned. Using the latest version is not recommended because it can mean permissions added to the document when it was most recently updated may not be respected.- Parameters:
searchResults
- the results of a search from this managerversionPolicy
- whether to retrieve the indexed version of content found via search (recommended), or the latest version of content (not recommended)- Returns:
- the entities represented by that search result. List may be empty if the search returned no results, or may contain null values where the result does not map to a valid database record.
- Since:
- 4.0
-
explain
Produce an explanation of the search query for the specified contentId. -
searchCategorised
default <T> Map<T,List<Map<String, searchCategorisedString>>> (ISearch search, SearchManager.Categorizer<T> categorizer) throws InvalidSearchException Perform a search with the given criteria, the top results are collected per category specified by the givenSearchManager.Categorizer
. If theISearch
contains noContentStatusQuery
in the search query or search filter tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.- Throws:
InvalidSearchException
- Since:
- 6.7
-
scan
long scan(EnumSet<SearchIndex> indexes, SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String, String[]>> consumer) throws InvalidSearchExceptionExecuteConsumer.accept(T)
for each search result. This method enables memory optimised implementation that doesn't need to allocate memory to hold the entire search result.If the
SearchQuery
contains noContentStatusQuery
in the query tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Returns:
- The total number of hits
- Throws:
InvalidSearchException
- Since:
- 7.9.0
-
scan
long scan(List<Index> indices, SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String, String[]>> consumer) throws InvalidSearchExceptionExecuteConsumer.accept(T)
for each search result. This method enables memory optimised implementation that doesn't need to allocate memory to hold the entire search result.If the
SearchQuery
contains noContentStatusQuery
in the query tree the result ofContentStatusQuery.getDefaultContentStatusQuery()
will be added as a top level AND query.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Returns:
- The total number of hits
- Throws:
InvalidSearchException
- Since:
- 8.7.0
-