Class SolrResponseFacetDecorator<F,V>
java.lang.Object
com.broadleafcommerce.search.provider.solr.response.SolrResponseFacetDecorator<F,V>
- Type Parameters:
F
- The type of Solr facet to read from theQueryResponse
to be used to populateFacetResponse
informationV
- The type of Solr facet value to read from the Solr facet to populateFacetValue
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
FieldsModifier and TypeFieldDescriptionprotected final com.broadleafcommerce.search.provider.solr.SolrFieldService
-
Constructor Summary
ConstructorsConstructorDescriptionSolrResponseFacetDecorator
(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.search.api.domain.Facet
buildFacetFromField
(com.broadleafcommerce.search.api.domain.FieldDefinition field) Grabs thefield's facet
, makes sure to hydrate any fields on it such asFacet.getName()
, and removes any unnecessary info likeFacet.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 theFacetResponse
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 theFacetValue
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 theFacetValues
for this facet and filters.<T extends com.broadleafcommerce.search.api.domain.SearchResponse>
voiddecorate
(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) AddFacetResponse
s for a facet type to theSearchResponse
.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 theFieldDefinition
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.getSolrFacets
(org.apache.solr.client.solrj.response.QueryResponse queryResponse) Retrieve the facets for this facet type from theQueryResponse
getSolrFacetValues
(F solrFacet) Retrieve the values with counts from the Solr facet.protected com.broadleafcommerce.search.provider.solr.SolrFieldService
protected com.broadleafcommerce.common.extension.TypeFactory
protected void
sortFacetResponses
(List<com.broadleafcommerce.search.api.domain.FacetResponse> facetResponses) Sort the facet responses in display order.
-
Field Details
-
solrFieldService
protected final com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService
-
-
Constructor Details
-
SolrResponseFacetDecorator
public SolrResponseFacetDecorator(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
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) AddFacetResponse
s for a facet type to theSearchResponse
.FacetResponse
s andFacetValue
s will be sorted by Display Order.- Specified by:
decorate
in interfaceSolrResponseDecorator
- Parameters:
searchResponse
- Search response to be updatedsearchRequest
- Original search requestqueryResponse
- Response from Solr for searchpage
- The requested page for the searchproperties
-context
- (optional) The context information surrounding sandboxing/multitenant statefieldDefinitions
- 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 typesearchRequest
- the original search requestqueryResponse
- 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 theQueryResponse
- 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 theFacetResponse
for the Solr facet based on the known fields and original search request.- Parameters:
fields
- all fields for the indexable typesolrFacet
- the facet from a Solr responsesearchRequest
- the original search request- Returns:
- if present, a FacetResponse built from the Solr facet
-
getSolrFacetFieldName
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 theFieldDefinition
containing the facet for the given field name and field type.- Parameters:
fields
- all fields for the indexable typename
- the name of the facet field to findtype
- 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 checkname
- the facet field name to findtype
- 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 forsearchRequest
- 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 thefield's facet
, makes sure to hydrate any fields on it such asFacet.getName()
, and removes any unnecessary info likeFacet.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 theFacetValues
for this facet and filters.- Parameters:
facet
- search facet to which this value belongssolrFacet
- facet from Solr responsesearchFilter
- current filter associated with this facet on search- Returns:
- search facet values for this type of facet
-
getSolrFacetValues
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 theFacetValue
for this facet value.- Parameters:
facet
- Search facet to which this value belongsvalue
- Facet value from Solr facetfacetFilter
- 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()
-