Package org.ametys.cms.search.solr
Class SearcherFactory.Searcher
java.lang.Object
org.ametys.cms.search.solr.SearcherFactory.Searcher
- Direct Known Subclasses:
FrontOfficeSearcherFactory.FrontOfficeSearcher
- Enclosing class:
- SearcherFactory
Class searching objects corresponding to a query, with optional sort, facets, and so on.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <A extends AmetysObject>
SearchResults<A>_buildResults(org.apache.solr.client.solrj.response.QueryResponse response, List<SearchField> facets) From the Solr server response, builds theSearchResultsobject.addContextElement(String key, Object value) Add a value to the search context.addFacet(SearchField facet) Add a faceted field.addFilterQuery(Query query) Add a filter query to the existing ones (as aQueryobject).addFilterQueryString(String query) Add a filter query to the existing ones (as a String).Add a sort clause to the existing ones.checkRightsComparingTo(AllowedUsers compareTo) Check rights when searching, not according to the current user, but according to the givenvisibiltyto compare each result with.getFacetResults(org.apache.solr.client.solrj.response.QueryResponse response, Collection<SearchField> facets) Retrieve the facet results from the solr response.Get the filter queries from the parameters.protected ObjectgetQuery()Get the query string from the parameters.protected org.ametys.cms.search.solr.SearcherFactory.AmetysQueryRequestgetSolrQuery(Object query, Collection<Object> filterQueries, int start, int maxResults, Map<String, Object> searchContext, boolean checkRights, AllowedUsers allowedUsersToCompare) Get the solr query object.protected voidmodifySolrQuery(org.apache.solr.client.solrj.request.json.JsonQueryRequest query) Template method to do additional operations on the Solr query before passing it to the Solr client<A extends AmetysObject>
AmetysObjectIterable<A>search()Execute the search with the current parameters.<A extends AmetysObject>
SearchResults<A>Execute the search with the current parameters.setCheckRights(boolean checkRights) Whether to check rights when searching, false otherwise.Sets the debug on the Solr queryprotected voidsetFacets(org.apache.solr.client.solrj.request.json.JsonQueryRequest solrQuery, Collection<SearchField> facets, Map<String, List<String>> facetValues) Set the facet definition in the solr query object and return a mapping from solr field name to criterion ID.protected voidsetSort(org.apache.solr.client.solrj.request.json.JsonQueryRequest solrQuery, List<Sort> sortCriteria) Set the sort definition in the solr query object.withContext(Map<String, Object> searchContext) Set the search context.withFacets(Collection<SearchField> facets) Set the faceted fields.withFacets(SearchField... facets) Set the faceted fields.withFacetValues(Map<String, List<String>> facetValues) Set the facet values.withFilterQueries(Collection<Query> queries) Set the filter queries (asQueryobjects).withFilterQueries(Query... queries) Set the filter queries (asQueryobjects).withFilterQueryStrings(String... queries) Set the filter queries (as Strings).withFilterQueryStrings(Collection<String> queries) Set the filter queries (as Strings).withLimits(int start, int maxResults) Set the search offset and limit.Set the query (as aQueryobject).withQueryString(String query) Set the query (as a String).Set the sort clauses.Set the sort clauses.
-
Constructor Details
-
Searcher
Build a Searcher with default values.- Parameters:
logger- The logger.
-
-
Method Details
-
withQueryString
Set the query (as a String).- Parameters:
query- the query (as a String).- Returns:
- The Searcher object itself.
-
withQuery
Set the query (as aQueryobject).- Parameters:
query- the query (as aQueryobject).- Returns:
- The Searcher object itself.
-
withFilterQueryStrings
Set the filter queries (as Strings).- Parameters:
queries- the filter queries (as Strings).- Returns:
- The Searcher object itself. The Searcher object itself.
-
withFilterQueryStrings
Set the filter queries (as Strings).- Parameters:
queries- the filter queries (as Strings).- Returns:
- The Searcher object itself. The Searcher object itself.
-
addFilterQueryString
Add a filter query to the existing ones (as a String).- Parameters:
query- the filter query to add (as a String).- Returns:
- The Searcher object itself. The Searcher object itself.
-
withFilterQueries
Set the filter queries (asQueryobjects).- Parameters:
queries- the filter queries (asQueryobjects).- Returns:
- The Searcher object itself. The Searcher object itself.
-
withFilterQueries
Set the filter queries (asQueryobjects).- Parameters:
queries- the filter queries (asQueryobjects).- Returns:
- The Searcher object itself. The Searcher object itself.
-
addFilterQuery
Add a filter query to the existing ones (as aQueryobject).- Parameters:
query- the filter query to add (as aQueryobject).- Returns:
- The Searcher object itself. The Searcher object itself.
-
withSort
Set the sort clauses.- Parameters:
sortClauses- the sort clauses.- Returns:
- The Searcher object itself.
-
withSort
Set the sort clauses.- Parameters:
sortClauses- the sort clauses.- Returns:
- The Searcher object itself.
-
addSort
Add a sort clause to the existing ones.- Parameters:
sortClause- The sort clause to add.- Returns:
- The Searcher object itself.
-
withFacets
Set the faceted fields.- Parameters:
facets- the faceted fields.- Returns:
- The Searcher object itself.
-
withFacets
Set the faceted fields.- Parameters:
facets- the faceted fields.- Returns:
- The Searcher object itself.
-
addFacet
Add a faceted field.- Parameters:
facet- The faceted field to add.- Returns:
- The Searcher object itself.
-
withFacetValues
Set the facet values.- Parameters:
facetValues- The facet values.- Returns:
- The Searcher object itself.
-
withLimits
Set the search offset and limit.- Parameters:
start- The start index (offset).maxResults- The maximum number of results.- Returns:
- The Searcher object itself.
-
withContext
Set the search context.- Parameters:
searchContext- The search context.- Returns:
- The Searcher object itself.
-
addContextElement
Add a value to the search context.- Parameters:
key- The context key.value- The value.- Returns:
- The Searcher object itself.
-
setCheckRights
Whether to check rights when searching, false otherwise.- Parameters:
checkRights-trueto check rights,falseotherwise.- Returns:
- The Searcher object itself.
-
checkRightsComparingTo
Check rights when searching, not according to the current user, but according to the givenvisibiltyto compare each result with.- Parameters:
compareTo- thevisibiltyto compare each result with.- Returns:
- The Searcher object itself.
-
setDebugOn
Sets the debug on the Solr query- Returns:
- The Searcher object itself.
-
search
Execute the search with the current parameters.- Type Parameters:
A- The type of search results- Returns:
- An iterable on the result ametys objects.
- Throws:
Exception- If an error occurs.
-
searchWithFacets
Execute the search with the current parameters.- Type Parameters:
A- The type of search results- Returns:
- An iterable on the search result objects.
- Throws:
Exception- If an error occurs.
-
_buildResults
protected <A extends AmetysObject> SearchResults<A> _buildResults(org.apache.solr.client.solrj.response.QueryResponse response, List<SearchField> facets) throws Exception From the Solr server response, builds theSearchResultsobject.- Type Parameters:
A- The type of search results- Parameters:
response- The response from the Solr serverfacets- The facet fields to return- Returns:
- An iterable on the search result objects.
- Throws:
Exception- If an error occurs.
-
getQuery
Get the query string from the parameters.- Returns:
- The query string.
- Throws:
QuerySyntaxException- If the query is invalid.
-
getFilterQueries
Get the filter queries from the parameters.- Returns:
- The list of filter queries.
- Throws:
QuerySyntaxException- If one of the queries is invalid.
-
getSolrQuery
protected org.ametys.cms.search.solr.SearcherFactory.AmetysQueryRequest getSolrQuery(Object query, Collection<Object> filterQueries, int start, int maxResults, Map<String, Object> searchContext, boolean checkRights, AllowedUsers allowedUsersToCompare) throws ExceptionGet the solr query object.- Parameters:
query- The solr query string.filterQueries- The filter queries (as Strings).start- The start index.maxResults- The maximum number of results.searchContext- The search context.checkRights- Whether to check rights when searching or not.allowedUsersToCompare- TheAllowedUsersobject to compare with for checking rights- Returns:
- The solr query object.
- Throws:
Exception- If an error occurs.
-
setSort
protected void setSort(org.apache.solr.client.solrj.request.json.JsonQueryRequest solrQuery, List<Sort> sortCriteria) Set the sort definition in the solr query object.- Parameters:
solrQuery- The solr query object.sortCriteria- The sort criteria.
-
setFacets
protected void setFacets(org.apache.solr.client.solrj.request.json.JsonQueryRequest solrQuery, Collection<SearchField> facets, Map<String, List<String>> facetValues) throws QuerySyntaxExceptionSet the facet definition in the solr query object and return a mapping from solr field name to criterion ID.- Parameters:
solrQuery- the solr query object to fill.facets- The facet definitions to use.facetValues- the facet values.- Throws:
QuerySyntaxException- if there's a syntax error in queries
-
getFacetResults
protected Map<String,Map<String, getFacetResultsInteger>> (org.apache.solr.client.solrj.response.QueryResponse response, Collection<SearchField> facets) Retrieve the facet results from the solr response.- Parameters:
response- the solr response.facets- The facet fields to return.- Returns:
- the facet results.
-
modifySolrQuery
Template method to do additional operations on the Solr query before passing it to the Solr client- Parameters:
query- the Solr query
-