Class DefaultSolrFacetContributor
java.lang.Object
com.broadleafcommerce.search.provider.solr.AbstractSolrQueryContributor
com.broadleafcommerce.search.provider.solr.DefaultSolrFacetContributor
- All Implemented Interfaces:
SolrQueryContributor
,org.springframework.core.Ordered
-
Field Summary
FieldsFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolrFacetContributor
(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.rulesengine.expression.context.ExpressionContext expressionContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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 providedsolrQuery
with some additional behavior.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 whichFieldDefinitions
with facets are applicable to thisSearchRequest
.protected boolean
filterMatchesFacetRule
(com.broadleafcommerce.search.api.domain.Facet facet, Map<String, String> filterParams) Determines if theFacet's
rule matches the filter parameters.protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContext
protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService
protected com.broadleafcommerce.search.core.service.facet.SearchFacetUtils<com.broadleafcommerce.search.api.domain.Facet>
protected com.broadleafcommerce.search.provider.solr.SolrFieldService
void
setSearchFacetUtils
(com.broadleafcommerce.search.core.service.facet.SearchFacetUtils<com.broadleafcommerce.search.api.domain.Facet> searchFacetUtils) 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.Methods inherited from class com.broadleafcommerce.search.provider.solr.AbstractSolrQueryContributor
contribute
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.search.provider.solr.SolrQueryContributor
contributeOnTypeAhead, getOrder, isTypeAheadRequest
-
Field Details
-
EMPTY_MAP
-
-
Constructor Details
-
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 Details
-
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 providedsolrQuery
with some additional behavior.- Specified by:
contributeInternal
in classAbstractSolrQueryContributor
- Parameters:
solrQuery
- The query to customizesearchRequest
- The search query requestfieldDefinitions
- The fields to perform the search onpage
- Page information for page to retrieve for queryproperties
- Additional properties for this querylocale
- The locale of this searchcontext
- 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 configurationfilters
- The filters from the search request.fieldDefinitions
- All field definitions for the type being queriedlocale
- (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 whichFieldDefinitions
with facets are applicable to thisSearchRequest
.- Parameters:
fieldDefinitions
- TheFieldDefinitions
to examine.filters
- TheFilter
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 fieldfield
- field with the ranged facetfilters
- The filters from the search requestlocale
- (optional) the locale of the query
-
buildFacetRanges
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 facetsolrQuery
- the Solr queryfacetFieldName
- the Solr name of the facet field to updatefilters
- 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 fieldfield
- field with the standard facetfilters
- The filters from the search requestlocale
- (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 facetfacetFieldName
- the Solr name of the facet field to updatefilters
- 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 forlocale
- (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 valuelist
takes precedence.- Parameters:
filters
- The filters to convert into a map.- Returns:
- A key/value map of
Filter
values. - See Also:
-
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 considerfilterParams
- 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 theFacet'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
- ifFacet.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 classAbstractSolrQueryContributor
- Parameters:
solrQuery
- The query to customizesearchRequest
- The search query requestpage
- Page information for page to retrieve for queryproperties
- Additional properties for this query.context
- The context information surrounding sandboxing/multitenant state- Returns:
- whether this contributor should run
-
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() -
setSearchFacetUtils
@Autowired public void setSearchFacetUtils(com.broadleafcommerce.search.core.service.facet.SearchFacetUtils<com.broadleafcommerce.search.api.domain.Facet> searchFacetUtils) - Since:
- 2.1.0-GA
-
getSearchFacetUtils
protected com.broadleafcommerce.search.core.service.facet.SearchFacetUtils<com.broadleafcommerce.search.api.domain.Facet> getSearchFacetUtils()- Since:
- 2.1.0-GA
-