Class SearcherFactory.Searcher

java.lang.Object
org.ametys.cms.search.solr.SearcherFactory.Searcher
Direct Known Subclasses:
FrontOfficeSearcherFactory.FrontOfficeSearcher
Enclosing class:
SearcherFactory

public class SearcherFactory.Searcher extends Object
Class searching objects corresponding to a query, with optional sort, facets, and so on.
  • Constructor Details

    • Searcher

      protected Searcher(Logger logger)
      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 a Query object).
      Parameters:
      query - the query (as a Query object).
      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 (as Query objects).
      Parameters:
      queries - the filter queries (as Query objects).
      Returns:
      The Searcher object itself. The Searcher object itself.
    • withFilterQueries

      Set the filter queries (as Query objects).
      Parameters:
      queries - the filter queries (as Query objects).
      Returns:
      The Searcher object itself. The Searcher object itself.
    • addFilterQuery

      Add a filter query to the existing ones (as a Query object).
      Parameters:
      query - the filter query to add (as a Query object).
      Returns:
      The Searcher object itself. The Searcher object itself.
    • withSort

      public SearcherFactory.Searcher withSort(Sort... sortClauses)
      Set the sort clauses.
      Parameters:
      sortClauses - the sort clauses.
      Returns:
      The Searcher object itself.
    • withSort

      public SearcherFactory.Searcher withSort(List<Sort> sortClauses)
      Set the sort clauses.
      Parameters:
      sortClauses - the sort clauses.
      Returns:
      The Searcher object itself.
    • addSort

      public SearcherFactory.Searcher addSort(Sort sortClause)
      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

      public SearcherFactory.Searcher withLimits(int start, int maxResults)
      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

      public SearcherFactory.Searcher setCheckRights(boolean checkRights)
      Whether to check rights when searching, false otherwise.
      Parameters:
      checkRights - true to check rights, false otherwise.
      Returns:
      The Searcher object itself.
    • checkRightsComparingTo

      Check rights when searching, not according to the current user, but according to the given visibilty to compare each result with.
      Parameters:
      compareTo - the visibilty to compare each result with.
      Returns:
      The Searcher object itself.
    • setDebugOn

      Sets the debug on the Solr query
      Returns:
      The Searcher object itself.
    • search

      public <A extends AmetysObject> AmetysObjectIterable<A> search() throws Exception
      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

      public <A extends AmetysObject> SearchResults<A> searchWithFacets() throws Exception
      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 the SearchResults object.
      Type Parameters:
      A - The type of search results
      Parameters:
      response - The response from the Solr server
      facets - The facet fields to return
      Returns:
      An iterable on the search result objects.
      Throws:
      Exception - If an error occurs.
    • getQuery

      protected Object getQuery() throws QuerySyntaxException
      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 Exception
      Get 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 - The AllowedUsers object 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 QuerySyntaxException
      Set 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,Integer>> getFacetResults(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

      protected void modifySolrQuery(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
      Parameters:
      query - the Solr query