Enabling custom facet value sequencing

You can order facet values based on the browsed category. For example, you can ensure that one computer manufacturer’s products top the search results list when the customer searches under Electronics. When the same customer does the same search under the Baby/Kids category, a different manufacturer can top that list.

Before you begin

Ensure that you are running WebSphere Commerce Version 8.0.4. In WebSphere Commerce 8.0.4, the postprocessor class SolrRESTSearchFacetQueryPostprocessor permits reordering of facet values according to specific requirements.

About this task

The order in which results are displayed can be set in the post-processing phase that follows successful query processing. You can enable facet value sequencing by extending SolrRESTSearchFacetQueryPostprocessor in a new post-processor class, and registering it with the search profile you want to use.

Procedure

  1. Enable ordering of facet values.
    1. Create a post-processor class, for example SolrRESTSearchCustomFacetQueryPostprocessor. This new class is an extension of the existing SolrRESTSearchFacetQueryPostprocessor class.
    2. Ensure that the new post-processor class overrides the following protected method
      protected Map<String, String> getFacetsAndOrderedSequences(String categoryId, List<String> facetFields)

      Following is the signature of the default SolrRESTSearchFacetQueryPostprocessor protected method. The extended class must override this method and return the Map object.

      /**
      * This method returns the desired ordered sequences of facet values of facet fields. 
      * In the map, <br> Facet field name is the key and comma seperated desired ordered 
      * sequence is the value. <br> 
      *  e.g :
      * mfName_ntk_cs=Borsati,Gusso,Versatil,Albini,Hermitage Collection,Luigi Valenti <br>
      * ads_f10001_ntk_cs=Gray,Blue,Green,Black  <br>
      *	
      * @param categoryId, is the current page category Id
      * @param facetFields, is the list of available facet fields whose values can be 
      * reordered. 
      * 
      * @return facetAndValueMap, is the Map object of Facet field name (Key) and desired 
      * ordered sequence (Values). <br>
      */
      
      protected Map<String, String> getFacetsAndOrderedSequences(String categoryId, List<String> facetFields)
  2. Enable the Search processor to use the new facet value sequencing logic.
    1. Edit or create the file WCDE_installdir\workspace\WC\xml\config\com.ibm.commerce.catalog-ext\wc-search.xml.
    2. Add the search profiles IBM_findProductsByCategory_Summary and IBM_findProductsByCategory to the file. Each search profile contains a postprocessor definition for the class you created in Step 1.a. To ensure that the class is used exclusively, disable the default post-processor, SolrRESTSearchFacetQueryPostprocessor, in both profiles (as shown in the bolded text in the following sample).
      <_config:profile name="IBM_findProductsByCategory" indexName="CatalogEntry">
         <_config:query>        
           <_config:postprocessor 
                classname="com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchFacetQueryPostprocessor" 
                enabled="false"/>                               
           <_config:postprocessor 
                classname="com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchCustomFacetQueryPostprocessor" />       
         </_config:query>
      </_config:profile>	
       	
      <_config:profile name="IBM_findProductsByCategory_Summary" indexName="CatalogEntry">
         <_config:query>        	
           <_config:postprocessor 
                classname="com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchFacetQueryPostprocessor" 
                enabled="false"/>
           <_config:postprocessor 
                classname="com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchCustomFacetQueryPostprocessor" />                                          
         </_config:query>
      </_config:profile>

Results