Class 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.

    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • 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 provided solrQuery 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 given FieldDefinition and this FieldQuery.
      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.
    • 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 provided solrQuery with some additional behavior.
        Specified by:
        contributeInternal in class AbstractSolrQueryContributor
        Parameters:
        solrQuery - The query to customize
        searchRequest - The search query request
        fieldDefinitions - The fields to perform the search on
        page - Page information for page to retrieve for query
        properties - Additional properties for this query
        locale - The locale of this search
        context - 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 by QueryType.getTypeQuery(String).
        Parameters:
        queryType - the custom query type to build the query for
        originalQuery - 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 on
        queryType - the custom query type to build the query fields for
        fieldQueries - the field queries for the query type
        locale - (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 type
        locale - (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 given FieldDefinition and this FieldQuery.
        Parameters:
        fieldDefinition - the field to get the query field name from
        fieldQuery - the specific field query to create the query field for
        locale - (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 class AbstractSolrQueryContributor
        Parameters:
        solrQuery - The query to customize
        searchRequest - The search query request
        page - Page information for page to retrieve for query
        properties - 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()