Class TypeAheadHighlightFieldsPreProcessor

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

    public class TypeAheadHighlightFieldsPreProcessor
    extends Object
    implements com.broadleafcommerce.search.core.service.TypeAheadPreProcessor<org.apache.solr.client.solrj.SolrQuery>

    Handles multiple functions related to highlighting fields in a TypeAhead request.

    1. This sets common highlight attributes used when executing a TypeAheadRequest, including building the highlight query
    2. Sets the query fields to be returned based on TypeAheadSuggestionConfiguration.getSuggestionFields()

    See the Solr highlighting documentation for specific information on available highlight parameters.

    • Field Summary

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

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeAheadHighlightFieldsPreProcessor​(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 String[] getHighlightFields​(List<com.broadleafcommerce.search.api.domain.FieldVariant> highLightFieldVariants, String locale)
      Get the Solr fields which should be highlighted.
      protected List<com.broadleafcommerce.search.api.domain.FieldVariant> getHighLightFieldVariants​(com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration)
      Get the specific field variants to highlight on.
      protected int getHighlightFragmentSize​(com.broadleafcommerce.search.api.domain.TypeAheadConfiguration configuration)
      Represents Solr's hl.fragsize parameter, or
      protected String getHighlightMethod()
      The highlight method to be used when executing a Solr query.
      protected com.broadleafcommerce.search.core.service.locale.LocaleHelper getLocaleHelper()  
      int getOrder()  
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      void preProcess​(org.apache.solr.client.solrj.SolrQuery query, com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest typeAheadRequest, com.broadleafcommerce.search.api.domain.TypeAheadConfiguration configuration, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)  
      protected void setHighlightParameters​(com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest request, org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration, List<com.broadleafcommerce.search.api.domain.FieldVariant> highLightFieldVariants, String locale)
      Configure the parameters necessary to activate result highlighting, as well as the query and which fields to highlight.
    • Constructor Detail

      • TypeAheadHighlightFieldsPreProcessor

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

      • preProcess

        public void preProcess​(org.apache.solr.client.solrj.SolrQuery query,
                               com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest typeAheadRequest,
                               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:
        preProcess in interface com.broadleafcommerce.search.core.service.TypeAheadPreProcessor<org.apache.solr.client.solrj.SolrQuery>
      • setHighlightParameters

        protected void setHighlightParameters​(com.broadleafcommerce.search.api.domain.typeahead.TypeAheadRequest request,
                                              org.apache.solr.client.solrj.SolrQuery solrQuery,
                                              com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration,
                                              List<com.broadleafcommerce.search.api.domain.FieldVariant> highLightFieldVariants,
                                              @Nullable
                                              String locale)
        Configure the parameters necessary to activate result highlighting, as well as the query and which fields to highlight.
        Parameters:
        request - the original type ahead search request
        solrQuery - the Solr query to configure parameters on
        typeAheadConfiguration - the configuration containing highlighting parameter values
        highLightFieldVariants - the specific field variants to highlight on
        locale - (optional) the locale of the query
      • getHighlightFields

        protected String[] getHighlightFields​(List<com.broadleafcommerce.search.api.domain.FieldVariant> highLightFieldVariants,
                                              @Nullable
                                              String locale)
        Get the Solr fields which should be highlighted.
        Parameters:
        highLightFieldVariants - the specific field variants to highlight on
        locale - (optional) the locale of the query
        Returns:
        the Solr fields which should be highlighted
      • getHighLightFieldVariants

        protected List<com.broadleafcommerce.search.api.domain.FieldVariant> getHighLightFieldVariants​(com.broadleafcommerce.search.api.domain.TypeAheadConfiguration typeAheadConfiguration)
        Get the specific field variants to highlight on.
        Parameters:
        typeAheadConfiguration - the configuration for which to get the highlight variants
        Returns:
        the specific field variants to highlight on
      • getHighlightFragmentSize

        @NonNull
        protected int getHighlightFragmentSize​(com.broadleafcommerce.search.api.domain.TypeAheadConfiguration configuration)

        Represents Solr's hl.fragsize parameter, or

         the approximate size, in characters, of fragments to consider for highlighting.
         

        See the Solr highlighting documentation for more information.

        Parameters:
        configuration - configuration for type ahead with highlighting fragment size
        Returns:
        the configured highlight fragment size, or default 30
      • getHighlightMethod

        protected String getHighlightMethod()
        The highlight method to be used when executing a Solr query.

        See the Solr highlighting documentation for more information on available highlighters.

        Returns:
        highlight method to be used
      • 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()