Class SolrResponseFacetDecorator<F,​V>

  • Type Parameters:
    F - The type of Solr facet to read from the QueryResponse to be used to populate FacetResponse information
    V - The type of Solr facet value to read from the Solr facet to populate FacetValue information
    All Implemented Interfaces:
    SolrResponseDecorator
    Direct Known Subclasses:
    SolrResponseRangedFacetDecorator, SolrResponseStandardFacetDecorator

    public abstract class SolrResponseFacetDecorator<F,​V>
    extends Object
    implements SolrResponseDecorator
    Implementations of this abstract class will populate some FacetResponse information on the SearchResponse.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService  
    • Constructor Summary

      Constructors 
      Constructor Description
      SolrResponseFacetDecorator​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.broadleafcommerce.search.api.domain.Facet buildFacetFromField​(com.broadleafcommerce.search.api.domain.FieldDefinition field)
      Grabs the field's facet, makes sure to hydrate any fields on it such as Facet.getName(), and removes any unnecessary info like Facet.getRanges().
      protected Optional<com.broadleafcommerce.search.api.domain.FacetResponse> buildFacetResponse​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, F solrFacet, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest)
      Build the FacetResponse for the Solr facet based on the known fields and original search request.
      protected List<com.broadleafcommerce.search.api.domain.FacetResponse> buildFacetResponses​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, org.apache.solr.client.solrj.response.QueryResponse queryResponse)
      Extract the facets from the QueryResponse and convert them into FacetResponses.
      protected abstract com.broadleafcommerce.search.api.domain.FacetValue buildFacetValue​(com.broadleafcommerce.search.api.domain.Facet facet, V value, com.broadleafcommerce.search.api.domain.Filter facetFilter)
      Create the FacetValue for this facet value.
      protected List<com.broadleafcommerce.search.api.domain.FacetValue> buildFacetValues​(com.broadleafcommerce.search.api.domain.Facet facet, F solrFacet, com.broadleafcommerce.search.api.domain.Filter searchFilter)
      Create the FacetValues for this facet and filters.
      <T extends com.broadleafcommerce.search.api.domain.SearchResponse>
      void
      decorate​(T searchResponse, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, org.apache.solr.client.solrj.response.QueryResponse queryResponse, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Add FacetResponses for a facet type to the SearchResponse.
      protected boolean facetMatchesField​(com.broadleafcommerce.search.api.domain.FieldDefinition field, String name, String type)
      Check if the field contains the facet matching the given name and type.
      protected com.broadleafcommerce.search.api.domain.Filter getFacetFilter​(com.broadleafcommerce.search.api.domain.FieldDefinition field, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest)
      Get the filter for a field from a search request.
      protected Optional<com.broadleafcommerce.search.api.domain.FieldDefinition> getFacetForField​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, String name, String type)
      Get the FieldDefinition containing the facet for the given field name and field type.
      protected abstract String getSolrFacetFieldName​(F solrFacet)
      Get the Solr field name for the facet.
      protected abstract List<F> getSolrFacets​(org.apache.solr.client.solrj.response.QueryResponse queryResponse)
      Retrieve the facets for this facet type from the QueryResponse
      protected abstract List<V> getSolrFacetValues​(F solrFacet)
      Retrieve the values with counts from the Solr facet.
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()  
      protected void sortFacetResponses​(List<com.broadleafcommerce.search.api.domain.FacetResponse> facetResponses)
      Sort the facet responses in display order.
    • Field Detail

      • solrFieldService

        protected final com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService
    • Constructor Detail

      • SolrResponseFacetDecorator

        public SolrResponseFacetDecorator​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService,
                                          com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • Method Detail

      • decorate

        public <T extends com.broadleafcommerce.search.api.domain.SearchResponse> void decorate​(T searchResponse,
                                                                                                com.broadleafcommerce.search.api.domain.SearchRequest searchRequest,
                                                                                                org.apache.solr.client.solrj.response.QueryResponse queryResponse,
                                                                                                List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                                                                                org.springframework.data.domain.Pageable page,
                                                                                                com.broadleafcommerce.search.core.service.SearchRequestProperties properties,
                                                                                                @Nullable
                                                                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Add FacetResponses for a facet type to the SearchResponse.

        FacetResponses and FacetValues will be sorted by Display Order.

        Specified by:
        decorate in interface SolrResponseDecorator
        Parameters:
        searchResponse - Search response to be updated
        searchRequest - Original search request
        queryResponse - Response from Solr for search
        page - The requested page for the search
        properties -
        context - (optional) The context information surrounding sandboxing/multitenant state
        fieldDefinitions - An unmodifiable list of field definitions used on the original search
      • buildFacetResponses

        protected List<com.broadleafcommerce.search.api.domain.FacetResponse> buildFacetResponses​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields,
                                                                                                  com.broadleafcommerce.search.api.domain.SearchRequest searchRequest,
                                                                                                  org.apache.solr.client.solrj.response.QueryResponse queryResponse)
        Extract the facets from the QueryResponse and convert them into FacetResponses.
        Parameters:
        fields - all fields for the indexable type
        searchRequest - the original search request
        queryResponse - the query response from Solr
        Returns:
        all facet responses extracted from the query response
      • getSolrFacets

        protected abstract List<F> getSolrFacets​(org.apache.solr.client.solrj.response.QueryResponse queryResponse)
        Retrieve the facets for this facet type from the QueryResponse
        Parameters:
        queryResponse - Response from Solr for search
        Returns:
        All facets of the type to process
      • buildFacetResponse

        protected Optional<com.broadleafcommerce.search.api.domain.FacetResponse> buildFacetResponse​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields,
                                                                                                     F solrFacet,
                                                                                                     com.broadleafcommerce.search.api.domain.SearchRequest searchRequest)
        Build the FacetResponse for the Solr facet based on the known fields and original search request.
        Parameters:
        fields - all fields for the indexable type
        solrFacet - the facet from a Solr response
        searchRequest - the original search request
        Returns:
        if present, a FacetResponse built from the Solr facet
      • getSolrFacetFieldName

        protected abstract String getSolrFacetFieldName​(F solrFacet)
        Get the Solr field name for the facet.
        Parameters:
        solrFacet - Facet from Solr
        Returns:
        Type-qualified Solr field name
      • getFacetForField

        protected Optional<com.broadleafcommerce.search.api.domain.FieldDefinition> getFacetForField​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields,
                                                                                                     String name,
                                                                                                     String type)
        Get the FieldDefinition containing the facet for the given field name and field type.
        Parameters:
        fields - all fields for the indexable type
        name - the name of the facet field to find
        type - the type of the facet field to find
        Returns:
        if present, the field containing the facet
      • facetMatchesField

        protected boolean facetMatchesField​(com.broadleafcommerce.search.api.domain.FieldDefinition field,
                                            String name,
                                            String type)
        Check if the field contains the facet matching the given name and type.
        Parameters:
        field - the field to check
        name - the facet field name to find
        type - the facet field type to find
        Returns:
        whether or not this field matches as a facet with this name and type
      • getFacetFilter

        @Nullable
        protected com.broadleafcommerce.search.api.domain.Filter getFacetFilter​(com.broadleafcommerce.search.api.domain.FieldDefinition field,
                                                                                com.broadleafcommerce.search.api.domain.SearchRequest searchRequest)
        Get the filter for a field from a search request.
        Parameters:
        field - the field to find a filter for
        searchRequest - the request to find a filter in
        Returns:
        the filter for this field on the search request
      • buildFacetFromField

        protected com.broadleafcommerce.search.api.domain.Facet buildFacetFromField​(com.broadleafcommerce.search.api.domain.FieldDefinition field)
        Grabs the field's facet, makes sure to hydrate any fields on it such as Facet.getName(), and removes any unnecessary info like Facet.getRanges().
        Parameters:
        field - Field from which to derive the facet for the response
        Returns:
        Facet with data massaged appropriately for a FacetResponse.
      • buildFacetValues

        protected List<com.broadleafcommerce.search.api.domain.FacetValue> buildFacetValues​(com.broadleafcommerce.search.api.domain.Facet facet,
                                                                                            F solrFacet,
                                                                                            @Nullable
                                                                                            com.broadleafcommerce.search.api.domain.Filter searchFilter)
        Create the FacetValues for this facet and filters.
        Parameters:
        facet - search facet to which this value belongs
        solrFacet - facet from Solr response
        searchFilter - current filter associated with this facet on search
        Returns:
        search facet values for this type of facet
      • getSolrFacetValues

        protected abstract List<V> getSolrFacetValues​(F solrFacet)
        Retrieve the values with counts from the Solr facet.
        Parameters:
        solrFacet - Facet from Solr
        Returns:
        Values for the facet
      • buildFacetValue

        protected abstract com.broadleafcommerce.search.api.domain.FacetValue buildFacetValue​(com.broadleafcommerce.search.api.domain.Facet facet,
                                                                                              V value,
                                                                                              @Nullable
                                                                                              com.broadleafcommerce.search.api.domain.Filter facetFilter)
        Create the FacetValue for this facet value.
        Parameters:
        facet - Search facet to which this value belongs
        value - Facet value from Solr facet
        facetFilter - Current filter associated with this facet on search
        Returns:
        Search facet value for this type of facet
      • sortFacetResponses

        protected void sortFacetResponses​(List<com.broadleafcommerce.search.api.domain.FacetResponse> facetResponses)
        Sort the facet responses in display order.
        Parameters:
        facetResponses - the facet responses to sort
      • getSolrFieldService

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

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()