public class SearcherFactory.Searcher extends Object
Modifier and Type | Field and Description |
---|---|
private boolean |
_checkRights |
private AllowedUsers |
_checkRightsComparingTo |
private boolean |
_debug |
private List<SearchField> |
_facets |
private Map<String,List<String>> |
_facetValues |
private List<Query> |
_filterQueries |
private List<String> |
_filterQueryStrings |
private Logger |
_logger |
private int |
_maxResults |
private Query |
_query |
private String |
_queryString |
private Map<String,Object> |
_searchContext |
private List<Sort> |
_sortClauses |
private int |
_start |
Modifier | Constructor and Description |
---|---|
protected |
Searcher(Logger logger)
Build a Searcher with default values.
|
Modifier and Type | Method and Description |
---|---|
protected <A extends AmetysObject> |
_buildResults(QueryResponse response,
List<SearchField> facets)
From the Solr server response, builds the
SearchResults object. |
private void |
_checkAllowedUsers(SolrQuery solrQuery,
AllowedUsers allowedUsersToCompare) |
private void |
_checkRightsQuery(SolrQuery solrQuery) |
private void |
_handleDebug(QueryResponse response) |
private void |
_logSearchQueries() |
private QueryResponse |
_querySolrServer() |
private void |
_setJoinedFacet(SolrQuery solrQuery,
String fieldName,
List<String> joinedPaths,
String solrFieldName,
String facetFunction,
Map<String,List<String>> facetValues) |
private void |
_setNonJoinedFacet(SolrQuery solrQuery,
String fieldName,
String solrFieldName,
Map<String,List<String>> facetValues) |
SearcherFactory.Searcher |
addContextElement(String key,
Object value)
Add a value to the search context.
|
SearcherFactory.Searcher |
addFacet(SearchField facet)
Add a faceted field.
|
SearcherFactory.Searcher |
addFilterQuery(Query query)
Add a filter query to the existing ones (as a
Query object). |
SearcherFactory.Searcher |
addFilterQueryString(String query)
Add a filter query to the existing ones (as a String).
|
SearcherFactory.Searcher |
addSort(Sort sortClause)
Add a sort clause to the existing ones.
|
SearcherFactory.Searcher |
checkRightsComparingTo(AllowedUsers compareTo)
Check rights when searching, not according to the current user,
but according to the given
visibilty to compare each
result with. |
protected Map<String,Map<String,Integer>> |
getFacetResults(QueryResponse response,
Collection<SearchField> facets)
Retrieve the facet results from the solr response.
|
protected List<String> |
getFilterQueries()
Get the filter queries from the parameters.
|
protected String |
getQuery()
Get the query string from the parameters.
|
protected SolrQuery |
getSolrQuery(String query,
Collection<String> filterQueries,
int start,
int maxResults,
Map<String,Object> searchContext,
boolean checkRights,
AllowedUsers allowedUsersToCompare)
Get the solr query object.
|
protected void |
modifySolrQuery(SolrQuery query)
Template method to do additional operations on the Solr query before passing it to the Solr client
|
<A extends AmetysObject> |
search()
Execute the search with the current parameters.
|
<A extends AmetysObject> |
searchWithFacets()
Execute the search with the current parameters.
|
SearcherFactory.Searcher |
setCheckRights(boolean checkRights)
Whether to check rights when searching, false otherwise.
|
SearcherFactory.Searcher |
setDebugOn()
Sets the debug on the Solr query
|
protected void |
setFacets(SolrQuery 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 void |
setSort(SolrQuery solrQuery,
List<Sort> sortCriteria)
Set the sort definition in the solr query object.
|
SearcherFactory.Searcher |
withContext(Map<String,Object> searchContext)
Set the search context.
|
SearcherFactory.Searcher |
withFacets(Collection<SearchField> facets)
Set the faceted fields.
|
SearcherFactory.Searcher |
withFacets(SearchField... facets)
Set the faceted fields.
|
SearcherFactory.Searcher |
withFacetValues(Map<String,List<String>> facetValues)
Set the facet values.
|
SearcherFactory.Searcher |
withFilterQueries(Collection<Query> queries)
Set the filter queries (as
Query objects). |
SearcherFactory.Searcher |
withFilterQueries(Query... queries)
Set the filter queries (as
Query objects). |
SearcherFactory.Searcher |
withFilterQueryStrings(Collection<String> queries)
Set the filter queries (as Strings).
|
SearcherFactory.Searcher |
withFilterQueryStrings(String... queries)
Set the filter queries (as Strings).
|
SearcherFactory.Searcher |
withLimits(int start,
int maxResults)
Set the search offset and limit.
|
SearcherFactory.Searcher |
withQuery(Query query)
Set the query (as a
Query object). |
SearcherFactory.Searcher |
withQueryString(String query)
Set the query (as a String).
|
SearcherFactory.Searcher |
withSort(List<Sort> sortClauses)
Set the sort clauses.
|
SearcherFactory.Searcher |
withSort(Sort... sortClauses)
Set the sort clauses.
|
private String _queryString
private List<String> _filterQueryStrings
private List<Query> _filterQueries
private List<Sort> _sortClauses
private List<SearchField> _facets
private Map<String,List<String>> _facetValues
private int _start
private int _maxResults
private Map<String,Object> _searchContext
private boolean _checkRights
private AllowedUsers _checkRightsComparingTo
private boolean _debug
public SearcherFactory.Searcher withQueryString(String query)
query
- the query (as a String).public SearcherFactory.Searcher withQuery(Query query)
Query
object).query
- the query (as a Query
object).public SearcherFactory.Searcher withFilterQueryStrings(String... queries)
queries
- the filter queries (as Strings).public SearcherFactory.Searcher withFilterQueryStrings(Collection<String> queries)
queries
- the filter queries (as Strings).public SearcherFactory.Searcher addFilterQueryString(String query)
query
- the filter query to add (as a String).public SearcherFactory.Searcher withFilterQueries(Query... queries)
Query
objects).queries
- the filter queries (as Query
objects).public SearcherFactory.Searcher withFilterQueries(Collection<Query> queries)
Query
objects).queries
- the filter queries (as Query
objects).public SearcherFactory.Searcher addFilterQuery(Query query)
Query
object).query
- the filter query to add (as a Query
object).public SearcherFactory.Searcher withSort(Sort... sortClauses)
sortClauses
- the sort clauses.public SearcherFactory.Searcher withSort(List<Sort> sortClauses)
sortClauses
- the sort clauses.public SearcherFactory.Searcher addSort(Sort sortClause)
sortClause
- The sort clause to add.public SearcherFactory.Searcher withFacets(SearchField... facets)
facets
- the faceted fields.public SearcherFactory.Searcher withFacets(Collection<SearchField> facets)
facets
- the faceted fields.public SearcherFactory.Searcher addFacet(SearchField facet)
facet
- The faceted field to add.public SearcherFactory.Searcher withFacetValues(Map<String,List<String>> facetValues)
facetValues
- The facet values.public SearcherFactory.Searcher withLimits(int start, int maxResults)
start
- The start index (offset).maxResults
- The maximum number of results.public SearcherFactory.Searcher withContext(Map<String,Object> searchContext)
searchContext
- The search context.public SearcherFactory.Searcher addContextElement(String key, Object value)
key
- The context key.value
- The value.public SearcherFactory.Searcher setCheckRights(boolean checkRights)
checkRights
- true
to check rights, false
otherwise.public SearcherFactory.Searcher checkRightsComparingTo(AllowedUsers compareTo)
visibilty
to compare each
result with.compareTo
- the visibilty
to compare each result with.public SearcherFactory.Searcher setDebugOn()
public <A extends AmetysObject> AmetysObjectIterable<A> search() throws Exception
A
- The type of search resultsException
- If an error occurs.public <A extends AmetysObject> SearchResults<A> searchWithFacets() throws Exception
A
- The type of search resultsException
- If an error occurs.protected <A extends AmetysObject> SearchResults<A> _buildResults(QueryResponse response, List<SearchField> facets) throws Exception
SearchResults
object.A
- The type of search resultsresponse
- The response from the Solr serverfacets
- The facet fields to returnException
- If an error occurs.private void _handleDebug(QueryResponse response)
private QueryResponse _querySolrServer() throws Exception
Exception
private void _logSearchQueries()
protected String getQuery() throws QuerySyntaxException
QuerySyntaxException
- If the query is invalid.protected List<String> getFilterQueries() throws QuerySyntaxException
QuerySyntaxException
- If one of the queries is invalid.protected SolrQuery getSolrQuery(String query, Collection<String> filterQueries, int start, int maxResults, Map<String,Object> searchContext, boolean checkRights, AllowedUsers allowedUsersToCompare) throws Exception
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
- The AllowedUsers
object to compare with for checking rightsException
- If an error occurs.private void _checkRightsQuery(SolrQuery solrQuery)
private void _checkAllowedUsers(SolrQuery solrQuery, AllowedUsers allowedUsersToCompare)
protected void setSort(SolrQuery solrQuery, List<Sort> sortCriteria)
solrQuery
- The solr query object.sortCriteria
- The sort criteria.protected void setFacets(SolrQuery solrQuery, Collection<SearchField> facets, Map<String,List<String>> facetValues)
solrQuery
- the solr query object to fill.facets
- The facet definitions to use.facetValues
- the facet values.private void _setJoinedFacet(SolrQuery solrQuery, String fieldName, List<String> joinedPaths, String solrFieldName, String facetFunction, Map<String,List<String>> facetValues)
private void _setNonJoinedFacet(SolrQuery solrQuery, String fieldName, String solrFieldName, Map<String,List<String>> facetValues)
protected Map<String,Map<String,Integer>> getFacetResults(QueryResponse response, Collection<SearchField> facets)
response
- the solr response.facets
- The facet fields to return.protected void modifySolrQuery(SolrQuery query)
query
- the Solr query