Class RelevancyRulesSolrQueryContributor
java.lang.Object
com.broadleafcommerce.search.provider.solr.AbstractSolrQueryContributor
com.broadleafcommerce.search.provider.solr.RelevancyRulesSolrQueryContributor
- All Implemented Interfaces:
SolrQueryContributor
,org.springframework.core.Ordered
This contributor is responsible for applying the query parser boost parameter to the solr query.
These are used to boost the results based on the relevancy rules for the provided context.
Requires the eDisMax Query Parser.
This contributor is also used in type ahead requests.
- Since:
- Search Service 2.2.0, Release Train 2.2.0
-
Field Summary
FieldsFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionRelevancyRulesSolrQueryContributor
(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.core.service.relevancyrule.RelevancyRuleUtils<com.broadleafcommerce.search.api.domain.RelevancyRule> relevancyRuleUtils, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.rulesengine.expression.context.ExpressionContext expressionContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyMatchingQueryBoostToQueryFields
(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boosted query field for theRelevancyRule
of typeDefaultRelevancyRuleTypes.MATCHING_VALUE
.protected void
attachRuleBoosts
(org.apache.solr.client.solrj.SolrQuery solrQuery, org.springframework.data.domain.Sort sorts, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, List<com.broadleafcommerce.search.api.domain.RelevancyRule> relevancyRules, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, String locale) Configure Solr result sorting with given page sort informationprotected void
buildBoostForField
(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField, List<String> boostFunctions, String locale) 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 relevancy rule evaluation.protected String
buildMatchingValueBoostFunction
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.MATCHING_VALUE
.protected String
buildOrdinalBoostFunction
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.ORDINAL
.protected String
buildRelativeBoostFunction
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.RELATIVE
.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
protected String
determineMatchingValueBoostedFunction
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String termFreqFunction) protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContext
protected com.broadleafcommerce.search.core.service.relevancyrule.RelevancyRuleUtils<com.broadleafcommerce.search.api.domain.RelevancyRule>
protected com.broadleafcommerce.search.api.domain.FieldVariant
getRelevancyRuleVariant
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, com.broadleafcommerce.search.api.domain.FieldDefinition ruleField) Retrieve theFieldVariant
to be used for the relevancy rule.protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService
protected String
getRuleField
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, String locale) Returns the Solr field name for the relevancy rule.protected com.broadleafcommerce.search.provider.solr.SolrFieldService
protected boolean
shouldApplyRule
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, String locale) protected boolean
shouldApplyRuleBasedOnCategoryContext
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, String locale) protected boolean
shouldApplyRuleBasedOnSearchTerm
(com.broadleafcommerce.search.api.domain.RelevancyRule rule, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, String locale) 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
-
Field Details
-
DEFAULT_BOOST_FUNCTION
-
FREQUENCY_BASE_VALUE
-
-
Constructor Details
-
RelevancyRulesSolrQueryContributor
public RelevancyRulesSolrQueryContributor(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.core.service.relevancyrule.RelevancyRuleUtils<com.broadleafcommerce.search.api.domain.RelevancyRule> relevancyRuleUtils, 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
-
attachRuleBoosts
protected void attachRuleBoosts(org.apache.solr.client.solrj.SolrQuery solrQuery, org.springframework.data.domain.Sort sorts, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, List<com.broadleafcommerce.search.api.domain.RelevancyRule> relevancyRules, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, @Nullable String locale) Configure Solr result sorting with given page sort information- Parameters:
solrQuery
- Query to execute in Solrsorts
- The sort optionsfieldDefinitions
- All field definitions for the type being queriedlocale
- (optional) the locale of the query
-
shouldApplyRule
-
shouldApplyRuleBasedOnSearchTerm
-
shouldApplyRuleBasedOnCategoryContext
-
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 relevancy 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:
-
defaultMap
- Returns:
- Returns an empty, unmodifiable map.
-
getRuleField
@Nullable protected String getRuleField(com.broadleafcommerce.search.api.domain.RelevancyRule rule, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, @Nullable String locale) Returns the Solr field name for the relevancy rule.- Parameters:
rule
- the requested relevancy rulefieldDefinitions
- All field definitions for the type being queriedlocale
- (optional) the locale of the query- Returns:
- the Solr field name for the relevancy rule
-
getRelevancyRuleVariant
@Nullable protected com.broadleafcommerce.search.api.domain.FieldVariant getRelevancyRuleVariant(com.broadleafcommerce.search.api.domain.RelevancyRule rule, com.broadleafcommerce.search.api.domain.FieldDefinition ruleField) Retrieve theFieldVariant
to be used for the relevancy rule.- Returns:
- variant to be used for the relevancy rule, or null
-
buildBoostForField
-
applyMatchingQueryBoostToQueryFields
protected void applyMatchingQueryBoostToQueryFields(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boosted query field for theRelevancyRule
of typeDefaultRelevancyRuleTypes.MATCHING_VALUE
.- Parameters:
solrQuery
- solrQuery Query to execute in Solrrule
- theRelevancyRule
to configure a boost forruleField
- the Solr field name that the boost should be applied to
-
buildMatchingValueBoostFunction
protected String buildMatchingValueBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.MATCHING_VALUE
. The default implementation of this method gets the term frequency of the field value and uses that to determine the computed boosted function. That computed boost function will be used if the term frequency is 1 or greater (if the term exists on the field). If the frequency is zero, the default boost function is returned.- Parameters:
rule
- theRelevancyRule
to configure a boost forruleField
- the Solr field name that the boost should be applied to- Returns:
- the boost function computed
-
determineMatchingValueBoostedFunction
-
buildOrdinalBoostFunction
protected String buildOrdinalBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.ORDINAL
. The default implementation of this method gets the order of the field (ascending by default, but can be configured on the rule to ascending), and multiplies it by the boost amount. The result is then compared with the minimum boundary configured on the rule & the higher value is returned.- Parameters:
rule
- theRelevancyRule
to configure a boost forruleField
- the Solr field name that the boost should be applied to- Returns:
- the boost function computed
-
buildRelativeBoostFunction
protected String buildRelativeBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRule
of typeDefaultRelevancyRuleTypes.RELATIVE
. The default implementation of this method adds one to the field value (to prevent division-by-zero errors), and then takes to inverse of that value. That inverted value is then multiplied by the boost amount. The result is then compared with the minimum boundary configured on the rule & the higher value is returned.- Parameters:
rule
- theRelevancyRule
to configure a boost forruleField
- the Solr field name that the boost should be applied to- Returns:
- the boost function computed
-
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, 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?
-
getSolrFieldService
protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService() -
getRelevancyRuleUtils
protected com.broadleafcommerce.search.core.service.relevancyrule.RelevancyRuleUtils<com.broadleafcommerce.search.api.domain.RelevancyRule> getRelevancyRuleUtils() -
getRuleEvaluationService
protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService getRuleEvaluationService() -
getExpressionContext
protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContext getExpressionContext()
-