Class TypeAheadSuggestionFieldsPostProcessor

  • All Implemented Interfaces:
    com.broadleafcommerce.search.core.service.TypeAheadPostProcessor<org.apache.solr.client.solrj.response.QueryResponse>, org.springframework.core.Ordered

    public class TypeAheadSuggestionFieldsPostProcessor
    extends Object
    implements com.broadleafcommerce.search.core.service.TypeAheadPostProcessor<org.apache.solr.client.solrj.response.QueryResponse>
    This PostProcessor is responsible for building recommended results on a TypeAhead query. Common use-cases are recommended categories or specific products. See TypeAheadSuggestionConfiguration for more information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String RESULT_COUNT  
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeAheadSuggestionFieldsPostProcessor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.core.service.locale.LocaleHelper localeHelper)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addFacetValues​(Map<String,​List<Map<String,​Object>>> suggestions, com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config, com.broadleafcommerce.search.api.domain.SuggestionField suggestionField, org.apache.solr.client.solrj.response.FacetField facetField)
      Populate the facet counts and names in the suggestion results for the field.
      protected void buildFacetResponse​(Map<String,​List<Map<String,​Object>>> suggestions, com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config, String locale, org.apache.solr.client.solrj.response.QueryResponse queryResponse)
      Build facet response for the type ahead response.
      protected void buildSuggestionFields​(com.broadleafcommerce.search.api.domain.typeahead.TypeAheadResponse response, String locale, List<com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration> configs, org.apache.solr.client.solrj.response.QueryResponse queryResponse)
      Populate the type-ahead suggestion items or facets for each type-ahead suggestion configuration.
      protected Map<String,​Object> buildSuggestionMap​(org.apache.solr.common.SolrDocument result, com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config, String locale)
      Build a suggestion result object for a type ahead result.
      protected void buildSuggestions​(Map<String,​List<Map<String,​Object>>> suggestions, com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config, String locale, org.apache.solr.client.solrj.response.QueryResponse queryResponse)
      Build suggestion results for the type ahead response.
      protected com.broadleafcommerce.search.core.service.locale.LocaleHelper getLocaleHelper()  
      int getOrder()  
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      protected boolean notReachedSizeLimit​(Map<String,​List<Map<String,​Object>>> suggestions, com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config)
      Check whether the suggestion results have been fully populated to their maximum size.
      void postProcess​(org.apache.solr.client.solrj.response.QueryResponse queryResponse, com.broadleafcommerce.search.api.domain.typeahead.TypeAheadResponse response, com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest request, com.broadleafcommerce.search.api.domain.TypeAheadConfiguration configuration, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)  
      protected boolean shouldProcess​(org.apache.solr.client.solrj.response.QueryResponse queryResponse, com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration)
      Whether suggestion fields should be processed.
    • Constructor Detail

      • TypeAheadSuggestionFieldsPostProcessor

        public TypeAheadSuggestionFieldsPostProcessor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService,
                                                      com.broadleafcommerce.search.core.service.locale.LocaleHelper localeHelper)
    • Method Detail

      • postProcess

        public void postProcess​(org.apache.solr.client.solrj.response.QueryResponse queryResponse,
                                com.broadleafcommerce.search.api.domain.typeahead.TypeAheadResponse response,
                                com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest request,
                                com.broadleafcommerce.search.api.domain.TypeAheadConfiguration configuration,
                                com.broadleafcommerce.search.core.service.SearchRequestProperties properties,
                                @Nullable
                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Specified by:
        postProcess in interface com.broadleafcommerce.search.core.service.TypeAheadPostProcessor<org.apache.solr.client.solrj.response.QueryResponse>
      • shouldProcess

        protected boolean shouldProcess​(org.apache.solr.client.solrj.response.QueryResponse queryResponse,
                                        com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration)
        Whether suggestion fields should be processed. Checks for existing TypeAheadConfiguration.getTypeAheadSuggestionConfigurations() and QueryResponse.getResults().
        Parameters:
        queryResponse - Solr query response to process
        typeAheadConfiguration - type ahead configuration for the type ahead query
        Returns:
        whether type ahead suggestion fields should be processed
      • buildSuggestionFields

        protected void buildSuggestionFields​(com.broadleafcommerce.search.api.domain.typeahead.TypeAheadResponse response,
                                             @Nullable
                                             String locale,
                                             List<com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration> configs,
                                             org.apache.solr.client.solrj.response.QueryResponse queryResponse)
        Populate the type-ahead suggestion items or facets for each type-ahead suggestion configuration.
        Parameters:
        response - TypeAhead response to process
        locale - (optional) the locale of the query
        configs - the configured type ahead suggestion groups
        queryResponse - Solr query response
      • buildFacetResponse

        protected void buildFacetResponse​(Map<String,​List<Map<String,​Object>>> suggestions,
                                          com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config,
                                          @Nullable
                                          String locale,
                                          org.apache.solr.client.solrj.response.QueryResponse queryResponse)
        Build facet response for the type ahead response.
        Parameters:
        suggestions - the suggested results for each field matched by the query
        config - the type ahead configuration
        locale - (optional) the locale of the query
        queryResponse - Solr query response
      • addFacetValues

        protected void addFacetValues​(Map<String,​List<Map<String,​Object>>> suggestions,
                                      com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config,
                                      com.broadleafcommerce.search.api.domain.SuggestionField suggestionField,
                                      org.apache.solr.client.solrj.response.FacetField facetField)
        Populate the facet counts and names in the suggestion results for the field.
        Parameters:
        suggestions - the suggested results for each field matched by the query
        config - the type ahead configuration
        suggestionField - the field in the suggested result matching the query
        facetField - the facet response for the suggestion field
      • buildSuggestions

        protected void buildSuggestions​(Map<String,​List<Map<String,​Object>>> suggestions,
                                        com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config,
                                        @Nullable
                                        String locale,
                                        org.apache.solr.client.solrj.response.QueryResponse queryResponse)
        Build suggestion results for the type ahead response.
        Parameters:
        suggestions - the suggested results for each field matched by the query
        config - the type ahead configuration
        locale - (optional) the locale of the query
        queryResponse - Solr query response
      • buildSuggestionMap

        protected Map<String,​Object> buildSuggestionMap​(org.apache.solr.common.SolrDocument result,
                                                              com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config,
                                                              @Nullable
                                                              String locale)
        Build a suggestion result object for a type ahead result.
        Parameters:
        result - the document result for the type ahead search
        config - the suggestion configuration indicating which fields to return in the result
        locale - (optional) the locale of the query
        Returns:
        a suggestion result object for a type ahead result
      • notReachedSizeLimit

        protected boolean notReachedSizeLimit​(Map<String,​List<Map<String,​Object>>> suggestions,
                                              com.broadleafcommerce.search.api.domain.TypeAheadSuggestionConfiguration config)
        Check whether the suggestion results have been fully populated to their maximum size.
        Parameters:
        suggestions - the suggestion results
        config - suggestion configuration including maximum number of suggestion results
        Returns:
        whether suggestion resutls are fully populated
      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered
      • getSolrFieldService

        protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()
      • getLocaleHelper

        protected com.broadleafcommerce.search.core.service.locale.LocaleHelper getLocaleHelper()