Customizing search mediators

A custom search mediator has access to both the logical noun object and the native Solr search result set object, SolrDocumentList.

For example, if the physical response object contains dynamic column definitions that must be programmatically mapped to logical UserData fields, a custom mediator can be used.

Procedure

  1. Create a class that extends from the com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.AbstractReadBusinessObjectPartMediatorImpl class.
  2. Overwrite the buildNounPart method, which takes noun and physicalEntity objects as input parameters. The noun object is the logical noun of the catalog navigation view noun, and the physicalEntity is the physical response that contains Solr documents.
    For example:
    
    package com.mycompany.commerce.catalog.facade.server.services.dataaccess.bom.mediator.solr;
    
    import java.util.Collection;
    import java.util.List;
    
    import org.apache.solr.common.SolrDocument;
    import org.apache.solr.common.SolrDocumentList;
    
    import com.ibm.commerce.catalog.facade.datatypes.CatalogEntryViewType;
    import com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType;
    import com.ibm.commerce.catalog.facade.server.services.search.metadata.solr.SolrCatalogNavigationViewImpl;
    import com.ibm.commerce.foundation.common.exception.AbstractApplicationException;
    import com.ibm.commerce.foundation.server.services.dataaccess.bom.mediator.AbstractReadBusinessObjectPartMediatorImpl;
    
    public class SolrReadCatalogEntryViewSamplePostMediator extends AbstractReadBusinessObjectPartMediatorImpl{
           
      public void buildNounPart(Object noun, Object physicalEntity)
          throws AbstractApplicationException {
    
        // Create logical types for catalog navigation
        CatalogNavigationViewType catalogNavigationView = (CatalogNavigationViewType) noun;
        
        // Get the physical entity populated with retrieved information
        SolrCatalogNavigationViewImpl entity = (SolrCatalogNavigationViewImpl) physicalEntity;
        
        if (entity != null && catalogNavigationView != null) {
          // get a list of the logical catalogEntryViews 
          List<CatalogEntryViewType> catalogEntryViews = catalogNavigationView.getCatalogEntryView();
          // get a list of the Solr documents          
          SolrDocumentList products = entity.getDocumentList();
                      
        
          if (products != null && catalogEntryViews !=null && products.size()== catalogEntryViews.size() ) {
            //Retrieve the dynamic column field and add it to the user user data field from each document
            for(int i=0;i<products.size();i++){
              SolrDocument product =  products.get(i);
              Collection<String> fields =  product.getFieldNames();
              for (String field : fields)  {            
                
                // Retrieve the field name and field value then put them into the userData
              }
            }
          }  
        }
      }
    }