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 voidapplyMatchingQueryBoostToQueryFields(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boosted query field for theRelevancyRuleof typeDefaultRelevancyRuleTypes.MATCHING_VALUE.protected voidattachRuleBoosts(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 voidbuildBoostForField(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 StringbuildMatchingValueBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRuleof typeDefaultRelevancyRuleTypes.MATCHING_VALUE.protected StringbuildOrdinalBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRuleof typeDefaultRelevancyRuleTypes.ORDINAL.protected StringbuildRelativeBoostFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String ruleField) Builds the boost function to apply for theRelevancyRuleof typeDefaultRelevancyRuleTypes.RELATIVE.protected voidcontributeInternal(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 providedsolrQuerywith some additional behavior.booleanprotected StringdetermineMatchingValueBoostedFunction(com.broadleafcommerce.search.api.domain.RelevancyRule rule, String termFreqFunction) protected com.broadleafcommerce.rulesengine.expression.context.ExpressionContextprotected com.broadleafcommerce.search.core.service.relevancyrule.RelevancyRuleUtils<com.broadleafcommerce.search.api.domain.RelevancyRule>protected com.broadleafcommerce.search.api.domain.FieldVariantgetRelevancyRuleVariant(com.broadleafcommerce.search.api.domain.RelevancyRule rule, com.broadleafcommerce.search.api.domain.FieldDefinition ruleField) Retrieve theFieldVariantto be used for the relevancy rule.protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationServiceprotected StringgetRuleField(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.SolrFieldServiceprotected booleanshouldApplyRule(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 booleanshouldApplyRuleBasedOnCategoryContext(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 booleanshouldApplyRuleBasedOnSearchTerm(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 booleanshouldContribute(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
contributeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:AbstractSolrQueryContributorCustomize the providedsolrQuerywith some additional behavior.- Specified by:
contributeInternalin 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 valuelisttakes precedence.- Parameters:
filters- The filters to convert into a map.- Returns:
- A key/value map of
Filtervalues. - 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 theFieldVariantto 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 theRelevancyRuleof typeDefaultRelevancyRuleTypes.MATCHING_VALUE.- Parameters:
solrQuery- solrQuery Query to execute in Solrrule- theRelevancyRuleto 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 theRelevancyRuleof 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- theRelevancyRuleto 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 theRelevancyRuleof 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- theRelevancyRuleto 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 theRelevancyRuleof 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- theRelevancyRuleto 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:AbstractSolrQueryContributorDetermines if this contributor should run.- Specified by:
shouldContributein 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()
-