Class DefaultSolrFacetContributor

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static Map<String,​String> EMPTY_MAP  
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSolrFacetContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.rulesengine.expression.context.ExpressionContext expressionContext)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addRangedFacetExclusion​(com.broadleafcommerce.search.api.domain.FieldDefinition facetField, org.apache.solr.client.solrj.SolrQuery solrQuery, String facetFieldName, List<com.broadleafcommerce.search.api.domain.Filter> filters)
      Update the facet range to exclude any active filters from the facet calculation.
      protected void attachFacets​(org.apache.solr.client.solrj.SolrQuery solrQuery, List<com.broadleafcommerce.search.api.domain.Filter> filters, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, String locale)
      Configure facets to enable facet responses for facets on this search type.
      protected void attachRangedFacet​(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.FieldDefinition field, List<com.broadleafcommerce.search.api.domain.Filter> filters, String locale)
      Attaches search facet ranges as Solr facet intervals.
      protected void attachStandardFacet​(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.FieldDefinition field, List<com.broadleafcommerce.search.api.domain.Filter> filters, String locale)
      Attaches a basic valued facet as a Solr facet field.
      protected String buildFacetFieldName​(com.broadleafcommerce.search.api.domain.FieldDefinition field, String locale)
      Build the Solr field name for the facetable type on the field.
      protected String buildFacetFieldWithExclusion​(com.broadleafcommerce.search.api.domain.FieldDefinition facetField, String facetFieldName, List<com.broadleafcommerce.search.api.domain.Filter> filters)
      Update a multi-select facet field name with tag to exclude any active filters from the facet calculation.
      protected String[] buildFacetRanges​(com.broadleafcommerce.search.api.domain.FieldDefinition field)
      Build an array of the ranges which this field can be faceted on.
      protected Map<String,​String> buildFilterParamsMap​(List<com.broadleafcommerce.search.api.domain.Filter> filters)
      Converts the filters in a set of filters to a key/value map to be used in Facet rule evaluation.
      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.
      protected Map<String,​String> defaultMap()  
      protected List<com.broadleafcommerce.search.api.domain.FieldDefinition> filterFacetableFields​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, List<com.broadleafcommerce.search.api.domain.Filter> filters)
      Determines which FieldDefinitions with facets are applicable to this SearchRequest.
      protected boolean filterMatchesFacetRule​(com.broadleafcommerce.search.api.domain.Facet facet, Map<String,​String> filterParams)
      Determines if the Facet's rule matches the filter parameters.
      protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContext getExpressionContext()  
      protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService getRuleEvaluationService()  
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      protected boolean shouldAttachFacet​(com.broadleafcommerce.search.api.domain.Facet facet, Map<String,​String> filterParams)
      Determine whether the facet should be included for the query based on current filters.
      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

      • DefaultSolrFacetContributor

        public DefaultSolrFacetContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService,
                                           com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService,
                                           com.broadleafcommerce.rulesengine.expression.context.ExpressionContext expressionContext)
    • 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
      • attachFacets

        protected void attachFacets​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                    List<com.broadleafcommerce.search.api.domain.Filter> filters,
                                    List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                    @Nullable
                                    String locale)
        Configure facets to enable facet responses for facets on this search type. An exclusion will be prepended for the names of the searchFilters active on the searchRequest, so that Facet counts are accurate in a multi-select scenario.
        Parameters:
        solrQuery - Query to attach facet configuration
        filters - The filters from the search request.
        fieldDefinitions - All field definitions for the type being queried
        locale - (optional) the locale of the query
      • filterFacetableFields

        protected List<com.broadleafcommerce.search.api.domain.FieldDefinition> filterFacetableFields​(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions,
                                                                                                      List<com.broadleafcommerce.search.api.domain.Filter> filters)
        Determines which FieldDefinitions with facets are applicable to this SearchRequest.
        Parameters:
        fieldDefinitions - The FieldDefinitions to examine.
        filters - The Filter filters to attach.
        Returns:
        A list of facetable FieldDefinitions applicable to this query.
      • attachRangedFacet

        protected void attachRangedFacet​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                         com.broadleafcommerce.search.api.domain.FieldDefinition field,
                                         List<com.broadleafcommerce.search.api.domain.Filter> filters,
                                         @Nullable
                                         String locale)
        Attaches search facet ranges as Solr facet intervals.
        Parameters:
        solrQuery - Query to attach facet field
        field - field with the ranged facet
        filters - The filters from the search request
        locale - (optional) the locale of the query
      • buildFacetRanges

        protected String[] buildFacetRanges​(com.broadleafcommerce.search.api.domain.FieldDefinition field)
        Build an array of the ranges which this field can be faceted on.
        Parameters:
        field - the field with facet ranges
        Returns:
        an array of the ranges which this field can be faceted on
      • addRangedFacetExclusion

        protected void addRangedFacetExclusion​(com.broadleafcommerce.search.api.domain.FieldDefinition facetField,
                                               org.apache.solr.client.solrj.SolrQuery solrQuery,
                                               String facetFieldName,
                                               List<com.broadleafcommerce.search.api.domain.Filter> filters)
        Update the facet range to exclude any active filters from the facet calculation.
        Parameters:
        facetField - field with the facet
        solrQuery - the Solr query
        facetFieldName - the Solr name of the facet field to update
        filters - the filters to exclude
      • attachStandardFacet

        protected void attachStandardFacet​(org.apache.solr.client.solrj.SolrQuery solrQuery,
                                           com.broadleafcommerce.search.api.domain.FieldDefinition field,
                                           List<com.broadleafcommerce.search.api.domain.Filter> filters,
                                           @Nullable
                                           String locale)
        Attaches a basic valued facet as a Solr facet field.
        Parameters:
        solrQuery - Query to attach facet field
        field - field with the standard facet
        filters - The filters from the search request
        locale - (optional) the locale of the query
      • buildFacetFieldWithExclusion

        protected String buildFacetFieldWithExclusion​(com.broadleafcommerce.search.api.domain.FieldDefinition facetField,
                                                      String facetFieldName,
                                                      List<com.broadleafcommerce.search.api.domain.Filter> filters)
        Update a multi-select facet field name with tag to exclude any active filters from the facet calculation.
        Parameters:
        facetField - field with the facet
        facetFieldName - the Solr name of the facet field to update
        filters - The filters to exclude
      • buildFacetFieldName

        @Nullable
        protected String buildFacetFieldName​(com.broadleafcommerce.search.api.domain.FieldDefinition field,
                                             @Nullable
                                             String locale)
        Build the Solr field name for the facetable type on the field.
        Parameters:
        field - the field to build the facet field name for
        locale - (optional) the locale of the query
        Returns:
        Solr field name for the facetable type on the field, or null if none is present
      • buildFilterParamsMap

        protected Map<String,​String> buildFilterParamsMap​(@Nullable
                                                                List<com.broadleafcommerce.search.api.domain.Filter> filters)
        Converts the filters in a set of filters to a key/value map to be used in Facet rule evaluation. Note that this implementation only supports a single filter key/value comparison, and the first item in the filter's value list takes precedence.
        Parameters:
        filters - The filters to convert into a map.
        Returns:
        A key/value map of Filter values.
        See Also:
        shouldAttachFacet(Facet, Map), filterMatchesFacetRule(Facet, Map), filterFacetableFields(List, List)
      • shouldAttachFacet

        protected boolean shouldAttachFacet​(com.broadleafcommerce.search.api.domain.Facet facet,
                                            Map<String,​String> filterParams)
        Determine whether the facet should be included for the query based on current filters.
        Parameters:
        facet - the facet to consider
        filterParams - the current filters
        Returns:
        whether the facet should be included
      • filterMatchesFacetRule

        protected boolean filterMatchesFacetRule​(com.broadleafcommerce.search.api.domain.Facet facet,
                                                 Map<String,​String> filterParams)
        Determines if the Facet's rule matches the filter parameters.
        Parameters:
        facet - The facet to evaluate with a non-null facet matching rule.
        filterParams - The filter parameters to evaluate against.
        Returns:
        true if rule matches, else false.
        Throws:
        IllegalArgumentException - if Facet.getFacetRule() is null or empty.
      • 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
      • defaultMap

        protected Map<String,​String> defaultMap()
        Returns:
        Returns an empty, unmodifiable map.
      • getSolrFieldService

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

        protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService getRuleEvaluationService()
      • getExpressionContext

        protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContext getExpressionContext()