public class LuceneSearchManager extends Object implements SearchManager
SearchManager.Categorizer<T>, SearchManager.EntityVersionPolicy
Constructor and Description |
---|
LuceneSearchManager(LuceneSearchMapper luceneSearchMapper,
com.atlassian.bonnie.analyzer.LuceneAnalyzerFactory luceneAnalyzerFactory,
com.atlassian.bonnie.ILuceneConnection luceneConnection,
SearchResultConverter converter,
com.atlassian.event.api.EventPublisher eventPublisher,
DarkFeaturesManager darkFeaturesManager) |
Modifier and Type | Method and Description |
---|---|
List<com.atlassian.bonnie.Searchable> |
convertToEntities(SearchResults searchResults,
SearchManager.EntityVersionPolicy versionPolicy)
Helper method to convert search results into a list of database entities.
|
String |
explain(ISearch search,
long contentId)
Produce an explanation of the search query for the specified contentId.
|
long |
scan(SearchFilter searchFilter,
Set<String> requestedFields,
Consumer<Map<String,String[]>> consumer)
Execute
Consumer.accept(T) for each search result. |
long |
scan(SearchQuery searchQuery,
Set<String> requestedFields,
Consumer<Map<String,String[]>> consumer)
Execute
Consumer.accept(T) for each search result. |
SearchResults |
search(ISearch search)
Perform a search with a given criteria.
|
SearchResults |
search(ISearch search,
Set<String> requestedFields)
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 |
search(SearchWithToken search)
Perform a search against a specific version of the search index (identified by calling
SearchWithToken.getSearchToken() on the specified search). |
<T> Map<T,List<Map<String,String>>> |
searchCategorised(ISearch search,
SearchManager.Categorizer<T> categorizer)
Perform a search with the given criteria, the top results are collected per category specified by the given
SearchManager.Categorizer . |
List<com.atlassian.bonnie.Searchable> |
searchEntities(ISearch search,
SearchManager.EntityVersionPolicy versionPolicy)
Perform a search with the given criteria, returning the results as a list of database entity
objects.
|
public LuceneSearchManager(LuceneSearchMapper luceneSearchMapper, com.atlassian.bonnie.analyzer.LuceneAnalyzerFactory luceneAnalyzerFactory, com.atlassian.bonnie.ILuceneConnection luceneConnection, SearchResultConverter converter, com.atlassian.event.api.EventPublisher eventPublisher, DarkFeaturesManager darkFeaturesManager)
public SearchResults search(SearchWithToken search) throws SearchTokenExpiredException, InvalidSearchException
SearchManager
Perform a search against a specific version of the search index (identified by calling SearchWithToken.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());
Note: Searches that declare a ResultFilter
will only be supported if the result filter is an instance of
SubsetResultFilter
.
search
in interface SearchManager
search
- a search that specifies a search token.SearchTokenExpiredException
- if the specified search token has expired. Clients should report this the user and / or retry the search with SearchManager.search(ISearch)
.InvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.public SearchResults search(ISearch search) throws InvalidSearchException
SearchManager
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.
search
in interface SearchManager
search
- the search to performInvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.public SearchResults search(ISearch search, Set<String> requestedFields) throws InvalidSearchException
SearchManager
FieldNotRequestedException
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.
search
in interface SearchManager
requestedFields
- requested fields. Passing null
will request all fields, and passing empty set will request none.InvalidSearchException
public List<com.atlassian.bonnie.Searchable> searchEntities(ISearch search, SearchManager.EntityVersionPolicy versionPolicy) throws InvalidSearchException
SearchManager
SearchManager.convertToEntities(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.
searchEntities
in interface SearchManager
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)InvalidSearchException
- when this manager is unable to translate and conduct the specified search. Clients should just discard the search if this occurs.public List<com.atlassian.bonnie.Searchable> convertToEntities(SearchResults searchResults, SearchManager.EntityVersionPolicy versionPolicy)
SearchManager
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 to SearchManager.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.
convertToEntities
in interface SearchManager
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)public <T> Map<T,List<Map<String,String>>> searchCategorised(ISearch search, SearchManager.Categorizer<T> categorizer) throws InvalidSearchException
SearchManager.Categorizer
.searchCategorised
in interface SearchManager
InvalidSearchException
public String explain(ISearch search, long contentId)
SearchManager
explain
in interface SearchManager
public long scan(SearchFilter searchFilter, Set<String> requestedFields, Consumer<Map<String,String[]>> consumer) throws InvalidSearchException
Consumer.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.scan
in interface SearchManager
InvalidSearchException
public long scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String,String[]>> consumer) throws InvalidSearchException
Consumer.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.scan
in interface SearchManager
InvalidSearchException
Copyright © 2003–2021 Atlassian. All rights reserved.