Class SearcherFactory.Searcher

    • Constructor Detail

      • Searcher

        protected Searcher​(org.slf4j.Logger logger)
        Build a Searcher with default values.
        Parameters:
        logger - The logger.
    • Method Detail

      • withFilterQueryStrings

        public SearcherFactory.Searcher withFilterQueryStrings​(String... queries)
        Set the filter queries (as Strings).
        Parameters:
        queries - the filter queries (as Strings).
        Returns:
        The Searcher object itself. The Searcher object itself.
      • addFilterQueryString

        public SearcherFactory.Searcher addFilterQueryString​(String query)
        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.
      • addFilterQuery

        public SearcherFactory.Searcher addFilterQuery​(Query query)
        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.
      • 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.
      • 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.
      • 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.
      • search

        public <A extends AmetysObjectAmetysObjectIterable<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.
      • _buildResults

        protected <A extends AmetysObjectSearchResults<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.
      • getSolrQuery

        protected org.apache.solr.client.solrj.SolrQuery getSolrQuery​(String query,
                                                                      Collection<String> 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.SolrQuery 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.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.
        Parameters:
        solrQuery - the solr query object to fill.
        facets - The facet definitions to use.
        facetValues - the facet values.
      • 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.SolrQuery query)
        Template method to do additional operations on the Solr query before passing it to the Solr client
        Parameters:
        query - the Solr query