Class DefaultSolrSortContributor

  • All Implemented Interfaces:
    SolrQueryContributor, org.springframework.core.Ordered

    public class DefaultSolrSortContributor
    extends AbstractSolrQueryContributor
    Handles attaching any relevant sorting (price, alphabetical, etc) to the search request.
    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSolrSortContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void attachSorts​(org.apache.solr.client.solrj.SolrQuery solrQuery, org.springframework.data.domain.Sort sorts, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, String locale)
      Configure Solr result sorting with given page sort information
      protected void contributeInternal​(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, String locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Customize the provided solrQuery with some additional behavior.
      boolean contributeOnTypeAhead()  
      int getOrder()
      Default Spring Bean ordering.
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      protected String getSortField​(org.springframework.data.domain.Sort.Order sort, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, String locale)
      Returns the Solr field name for the field to sort on.
      protected Optional<com.broadleafcommerce.search.api.domain.FieldDefinition> getSortFieldForProperty​(String property, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions)
      Get the FieldDefinition for the requested property to sort on.
      protected org.apache.solr.client.solrj.SolrQuery.ORDER getSortOrder​(org.springframework.data.domain.Sort.Order sort)
      Convert the requested sort order into a Solr compatible order.
      protected boolean shouldContribute​(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Determines if this contributor should run.
    • Constructor Detail

      • DefaultSolrSortContributor

        public DefaultSolrSortContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService)
    • Method Detail

      • contributeInternal

        protected void contributeInternal​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                          com.broadleafcommerce.search.api.domain.SearchRequest searchRequest,
                                          List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                          org.springframework.data.domain.Pageable page,
                                          com.broadleafcommerce.search.core.service.SearchRequestProperties properties,
                                          @Nullable
                                          String locale,
                                          @Nullable
                                          com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from class: AbstractSolrQueryContributor
        Customize the provided solrQuery with some additional behavior.
        Specified by:
        contributeInternal in class AbstractSolrQueryContributor
        Parameters:
        solrQuery - The query to customize
        searchRequest - The search query request
        fieldDefinitions - The fields to perform the search on
        page - Page information for page to retrieve for query
        properties - Additional properties for this query
        locale - The locale of this search
        context - The context information surrounding sandboxing/multitenant state
      • attachSorts

        protected void attachSorts​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                   org.springframework.data.domain.Sort sorts,
                                   List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                   @Nullable
                                   String locale)
        Configure Solr result sorting with given page sort information
        Parameters:
        solrQuery - Query to execute in Solr
        sorts - The sort options
        fieldDefinitions - All field definitions for the type being queried
        locale - (optional) the locale of the query
      • getSortField

        @Nullable
        protected String getSortField​(org.springframework.data.domain.Sort.Order sort,
                                      List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                      @Nullable
                                      String locale)
        Returns the Solr field name for the field to sort on.
        Parameters:
        sort - the requested sort
        fieldDefinitions - All field definitions for the type being queried
        locale - (optional) the locale of the query
        Returns:
        the Solr field name for the field to sort on, or null if none
      • getSortFieldForProperty

        protected Optional<com.broadleafcommerce.search.api.domain.FieldDefinition> getSortFieldForProperty​(String property,
                                                                                                            List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions)
        Get the FieldDefinition for the requested property to sort on.
        Parameters:
        property - the requested property to sort on
        fieldDefinitions - All field definitions for the type being queried
        Returns:
        if present, the field definition matching the sort property
      • getSortOrder

        protected org.apache.solr.client.solrj.SolrQuery.ORDER getSortOrder​(org.springframework.data.domain.Sort.Order sort)
        Convert the requested sort order into a Solr compatible order.
        Parameters:
        sort - the requested sort
        Returns:
        Solr order to sort by, either ascending or descending
      • shouldContribute

        protected boolean shouldContribute​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                           com.broadleafcommerce.search.api.domain.SearchRequest searchRequest,
                                           org.springframework.data.domain.Pageable page,
                                           com.broadleafcommerce.search.core.service.SearchRequestProperties properties,
                                           @Nullable
                                           com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from class: AbstractSolrQueryContributor
        Determines if this contributor should run.
        Specified by:
        shouldContribute in class AbstractSolrQueryContributor
        Parameters:
        solrQuery - The query to customize
        searchRequest - The search query request
        page - Page information for page to retrieve for query
        properties - Additional properties for this query.
        context - The context information surrounding sandboxing/multitenant state
        Returns:
        whether this contributor should run
      • contributeOnTypeAhead

        public boolean contributeOnTypeAhead()
        Returns:
        Should this contributor be executed on TypeAhead requests?
      • getOrder

        public int getOrder()
        Description copied from interface: SolrQueryContributor
        Default Spring Bean ordering.
      • getSolrFieldService

        protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()