Class QueryTypeSolrQueryContributor
- java.lang.Object
-
- com.broadleafcommerce.search.provider.solr.AbstractSolrQueryContributor
-
- com.broadleafcommerce.search.provider.solr.QueryTypeSolrQueryContributor
-
- All Implemented Interfaces:
SolrQueryContributor
,org.springframework.core.Ordered
public class QueryTypeSolrQueryContributor extends AbstractSolrQueryContributor
Replace standard query with typed queries to include custom querying and boosts on query type / field combinations.More specific boosts will override less specific boosts. If a field has a boost value for a particular query type, that will be preferred over a boost set for the field in general.
-
-
Constructor Summary
Constructors Constructor Description QueryTypeSolrQueryContributor(com.broadleafcommerce.search.core.service.locale.LocaleHelper localeHelper, com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, List<QueryType> queryTypes, com.broadleafcommerce.search.provider.solr.DefaultSolrSearchProvider solrSearchProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
buildQueryForQueryType(QueryType queryType, String originalQuery)
Build a query for the query type which applies its custom matching criteria.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.boolean
contributeOnTypeAhead()
protected String
getBoostedQueryField(com.broadleafcommerce.search.api.domain.FieldDefinition fieldDefinition, com.broadleafcommerce.search.api.domain.FieldQuery fieldQuery, String locale, Set<String> solrFields)
Retrieve the boosted Solr query field for the givenFieldDefinition
and thisFieldQuery
.protected com.broadleafcommerce.search.api.type.IndexableType
getIndexableType(org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries)
protected com.broadleafcommerce.search.core.service.locale.LocaleHelper
getLocaleHelper()
protected Map<QueryType,org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery>>
getQueriesForQueryTypes(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions)
Calculate the queries which should be applied for each query type and each field.protected String
getQueryFields(org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries, String locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Compile the field definitions from the field queries with their applicable boosts into a space delimited String of query fields to apply to the query type alias.protected List<QueryType>
getQueryTypes()
protected com.broadleafcommerce.search.provider.solr.SolrFieldService
getSolrFieldService()
protected com.broadleafcommerce.search.provider.solr.DefaultSolrSearchProvider
getSolrSearchProvider()
protected boolean
isSearchableFieldWithFieldQueries(com.broadleafcommerce.search.api.domain.FieldDefinition fieldDefinition)
protected void
populateQueryTypeQueryFields(org.apache.solr.client.solrj.SolrQuery solrQuery, QueryType queryType, org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries, String locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Populate the query fields for the query type and include any boosts.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
getOrder, isTypeAheadRequest
-
-
-
-
Constructor Detail
-
QueryTypeSolrQueryContributor
public QueryTypeSolrQueryContributor(com.broadleafcommerce.search.core.service.locale.LocaleHelper localeHelper, com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, List<QueryType> queryTypes, @Nullable com.broadleafcommerce.search.provider.solr.DefaultSolrSearchProvider solrSearchProvider)
-
-
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 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
-
getQueriesForQueryTypes
protected Map<QueryType,org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery>> getQueriesForQueryTypes(List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions)
Calculate the queries which should be applied for each query type and each field.- Parameters:
fieldDefinitions
- All field definitions for the type being queried- Returns:
- a map of each
QueryType
to the field queries which should be applied for each field for that type
-
isSearchableFieldWithFieldQueries
protected boolean isSearchableFieldWithFieldQueries(com.broadleafcommerce.search.api.domain.FieldDefinition fieldDefinition)
-
buildQueryForQueryType
protected String buildQueryForQueryType(QueryType queryType, String originalQuery)
Build a query for the query type which applies its custom matching criteria. The query type has an alias field to search on, and the search value is determined byQueryType.getTypeQuery(String)
.- Parameters:
queryType
- the custom query type to build the query fororiginalQuery
- the original, non-typed query- Returns:
- query formatted to support the matching associated with the query type
-
populateQueryTypeQueryFields
protected void populateQueryTypeQueryFields(org.apache.solr.client.solrj.SolrQuery solrQuery, QueryType queryType, org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries, @Nullable String locale, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Populate the query fields for the query type and include any boosts. The query fields will be populated to specifically apply to the query type alias field.- Parameters:
solrQuery
- the Solr query to populate parameters onqueryType
- the custom query type to build the query fields forfieldQueries
- the field queries for the query typelocale
- (optional) the locale of the query
-
getQueryFields
protected String getQueryFields(org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries, @Nullable String locale, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Compile the field definitions from the field queries with their applicable boosts into a space delimited String of query fields to apply to the query type alias.- Parameters:
fieldQueries
- the field queries for the query typelocale
- (optional) the locale of the query- Returns:
- space delimited query fields for query type alias
-
getIndexableType
protected com.broadleafcommerce.search.api.type.IndexableType getIndexableType(org.springframework.util.MultiValueMap<com.broadleafcommerce.search.api.domain.FieldDefinition,com.broadleafcommerce.search.api.domain.FieldQuery> fieldQueries)
-
getBoostedQueryField
@Nullable protected String getBoostedQueryField(com.broadleafcommerce.search.api.domain.FieldDefinition fieldDefinition, com.broadleafcommerce.search.api.domain.FieldQuery fieldQuery, @Nullable String locale, @Nullable Set<String> solrFields)
Retrieve the boosted Solr query field for the givenFieldDefinition
and thisFieldQuery
.- Parameters:
fieldDefinition
- the field to get the query field name fromfieldQuery
- the specific field query to create the query field forlocale
- (optional) the locale of the query- Returns:
- boosted Solr query field for query type alias
-
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
-
contributeOnTypeAhead
public boolean contributeOnTypeAhead()
- Returns:
- Should this contributor be executed on TypeAhead requests?
-
getLocaleHelper
protected com.broadleafcommerce.search.core.service.locale.LocaleHelper getLocaleHelper()
-
getSolrFieldService
protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()
-
getSolrSearchProvider
protected com.broadleafcommerce.search.provider.solr.DefaultSolrSearchProvider getSolrSearchProvider()
-
-