cancel
Showing results for 
Search instead for 
Did you mean: 

Custom enum facet not displaying on frontend

Former Member
0 Kudos

I am trying to create a custom enum facet on storefront , please let me know what am I missing, I tried below configurations:

Solr.impex

 INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];facet[default=true];facetType(code);facetSort(code);priority;visible;useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;facetDisplayNameProvider;customFacetSortProvider;topValuesProvider;rangeSets(name)
 ;$solrIndexedType; area;             string ;    ;true ;     ;true ;     ;MultiSelectOr ;Custom;10000;true;     ;     ;productAreaResolver;abcProductFacetDisplayNameResolver;
 

Resolver:

 public class ProductAreaResolver extends AbstractValueResolver<ProductModel, Object, Object>
 {
 
 
     /*
      * (non-Javadoc)
      *
      * @see de.hybris.platform.solrfacetsearch.provider.impl.AbstractValueResolver#addFieldValues(de.hybris.platform.
      * solrfacetsearch.indexer.spi.InputDocument, de.hybris.platform.solrfacetsearch.indexer.IndexerBatchContext,
      * de.hybris.platform.solrfacetsearch.config.IndexedProperty, de.hybris.platform.core.model.ItemModel,
      * de.hybris.platform.solrfacetsearch.provider.impl.AbstractValueResolver.ValueResolverContext)
      */
     @Override
     protected void addFieldValues(final InputDocument document, final IndexerBatchContext indexerBatchContext,
             final IndexedProperty indexedProperty, final ProductModel product,
             final ValueResolverContext<Object, Object> resolverContext) throws FieldValueProviderException
     {
 
 
         document.addField(indexedProperty, product.getArea(), resolverContext.getFieldQualifier());
 
     }
 }

Display Name Resolver:

 /*
  * [y] hybris Platform
  *
  * Copyright (c) 2018 SAP SE or an SAP affiliate company.  All rights reserved.
  *
  * This software is the confidential and proprietary information of SAP
  * ("Confidential Information"). You shall not disclose such Confidential
  * Information and shall use it only in accordance with the terms of the
  * license agreement you entered into with SAP.
  */
 package de.hybris.training.search.solrfacetsearch.provider.impl;
 
 import de.hybris.platform.core.HybrisEnumValue;
 import de.hybris.platform.enumeration.EnumerationService;
 import de.hybris.platform.servicelayer.i18n.CommonI18NService;
 import de.hybris.platform.servicelayer.i18n.I18NService;
 import de.hybris.platform.solrfacetsearch.config.IndexedProperty;
 import de.hybris.platform.solrfacetsearch.provider.impl.AbstractFacetValueDisplayNameProvider;
 import de.hybris.platform.solrfacetsearch.search.SearchQuery;
 import de.hybris.training.core.enums.AvailabilityEnum;
 
 import java.util.Locale;
 
 import org.springframework.beans.factory.annotation.Required;
 
 
 public class AbcProductFacetDisplayNameResolver extends AbstractFacetValueDisplayNameProvider
 {
     private EnumerationService enumerationService;
     private I18NService i18nService;
     private CommonI18NService commonI18NService;
 
     @Override
     public String getDisplayName(final SearchQuery query, final IndexedProperty property, final String facetValue)
     {
         if (facetValue == null)
         {
             return "";
         }
 
         final HybrisEnumValue availEnumValue = getEnumerationService().getEnumerationValue(AvailabilityEnum.class, facetValue);
 
         Locale queryLocale = null;
         if (query == null || query.getLanguage() == null || query.getLanguage().isEmpty())
         {
             queryLocale = getI18nService().getCurrentLocale();
         }
 
         if (queryLocale == null && query != null)
         {
             queryLocale = getCommonI18NService().getLocaleForLanguage(getCommonI18NService().getLanguage(query.getLanguage()));
         }
 
         String availName = getEnumerationService().getEnumerationName(availEnumValue, queryLocale);
         if (availName == null || availName.isEmpty())
         {
             availName = facetValue;
         }
 
         return availName;
     }
 
     protected EnumerationService getEnumerationService()
     {
         return enumerationService;
     }
 
     @Required
     public void setEnumerationService(final EnumerationService enumerationService)
     {
         this.enumerationService = enumerationService;
     }
 
     protected I18NService getI18nService()
     {
         return i18nService;
     }
 
     @Required
     public void setI18nService(final I18NService i18nService)
     {
         this.i18nService = i18nService;
     }
 
     protected CommonI18NService getCommonI18NService()
     {
         return commonI18NService;
     }
 
     @Required
     public void setCommonI18NService(final CommonI18NService commonI18NService)
     {
         this.commonI18NService = commonI18NService;
     }
 }
 

Bean Entry :

 <bean id="productAreaResolver" class="de.hybris.training.search.solrfacetsearch.provider.impl.ProductAreaResolver" parent="abstractPropertyFieldValueProvider">
   <property name="fieldNameProvider" ref="solrFieldNameProvider"/>
     </bean>
         
     <bean id="abcProductFacetDisplayNameResolver"
           class="de.hybris.training.search.solrfacetsearch.provider.impl.AbcProductFacetDisplayNameResolver"
           >
         <property name="enumerationService" ref="enumerationService"/>
         <property name="i18nService" ref="i18nService"/>
         <property name="commonI18NService" ref="commonI18NService"/>
     </bean>

   


Items.xml

 <enumtype code="AvailabilityEnum" generate="true" autocreate="true"
             dynamic="true">
             <value code="AVAILABLE_ACROSS_CITY" />
             <value code="AVAILABLE_IN_MARKET" />
             <value code="AVAILABLE_IN_SHOP" />
         </enumtype>
 <typegroup name="Area">
         <itemtype generate="false" code="Product" autocreate="false"> 
                 <attributes>
                     <attribute qualifier="area" type="AvailabilityEnum" autocreate="true">
                         <persistence type="property" />
                         </attribute>
                 </attributes>
             </itemtype>
         </typegroup>    

I have seen below value of product in Solr Admin :

 "area_string_mv":["AVAILABLE_IN_MARKET"],




Accepted Solutions (0)

Answers (0)