cancel
Showing results for 
Search instead for 
Did you mean: 

Can we create another solrindextype other than product type in same solrsearchconfig?

0 Kudos

Hi Experts, we have requirement to index another solrindextype which is totally different from product type.We have to use solr to search the new item type and display the search result on the specific searchpage. Can we create new solrindextype and index that itemtype on the solr? Any help regarding this will be very helpful. Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dhiraj,

It is possible and it is quite simple as the product flow. Take example of category. For indexing category following steps are required:

Step:1. So you need to create index and create index property and value provider as well if required.

 Solr.impex
  
  INSERT_UPDATE SolrIndexedType;identifier[unique=true];type(code);variant;sorts(&sortRefID);;;;;;;;;;;;;;;;
  ;$solrCategoryIndexedType;Category;false;;;;;;;;;;;;;;;;;
  
  INSERT_UPDATE SolrFacetSearchConfig;name[unique=true];description;indexNamePrefix;languages(isocode);currencies(isocode);solrServerConfig(name);solrSearchConfig(description);solrIndexConfig(name);solrIndexedTypes(identifier);enabledLanguageFallbackMechanism;$catalogVersions;;;;;;;;;
  ;$facetSearchConfigName;$facetSearchConfigDescription;$searchIndexNamePrefix;$indexLanguages;$indexCurrencies;$serverConfigName;$searchConfigName;$indexConfigName;$solrIndexedType,$solrCategoryIndexedType;true;$productCatalog:Online,$contentCatalog:Online;;;;;;;;;
  
  
  INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter;;;;;;;;;
  ;$solrCategoryIndexedType; code                   ;string ;            ;    ;    ;    ;;;;;;;;;;;;;
  ;$solrCategoryIndexedType; name                   ;text   ;sortabletext;    ;true;    ;;;;;;;;;;;;;
  
  
  INSERT_UPDATE SolrIndexerQuery;solrIndexedType(identifier)[unique=true];identifier[unique=true];type(code);injectCurrentDate[default=true];injectCurrentTime[default=true];injectLastIndexTime[default=true];query;user(uid);;;;;;;;;;;;
  ;$solrCategoryIndexedType;$searchIndexNamePrefix-fullCategoryQuery;full;;;true;select {c:PK} from {Category as c};anonymous;;;;;;;;;;;;

Step : 2 Need some provider if required. So value provider is used for fetching values from model and pass it to solr for indexing. Suppose you have newattribute. You need followinhg

Solr.impex:

 INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true];type(code);localized[default=false];multiValue[default=true];categoryField[default=true];useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;;;;;;;;;;;
  ;$categoryIndexType; contentType                ;string ;            ;false;    ;    ;    ;categorynewAttributeHeightValueProvider;;;;;;;;;;;

CategorynewAttributeHeightValueProvider.java

 public class ProductnewAttributeHeightValueProvider extends
          AbstractPropertyFieldValueProvider implements FieldValueProvider,
          Serializable {
  
      private static final long serialVersionUID = 1L;
      private FieldNameProvider fieldNameProvider;
  
      @Override
      public Collection<FieldValue> getFieldValues(final IndexConfig indexConfig,
              final IndexedProperty indexedProperty, final Object model)
              throws FieldValueProviderException {
          
          if (categoryModel== null) {
              return Collections.emptyList();
  
          }
  
          final String newAttribute = categoryModel.getNewAttribute();
  
          if (null != height) {
              final Collection<FieldValue> fieldValues = new ArrayList<FieldValue>();
              fieldValues.addAll(createFieldValue(newAttribute, indexedProperty));
              return fieldValues;
  
          } else {
              return Collections.emptyList();
          }
      }
  
      protected List<FieldValue> createFieldValue(final String newAttribute,
              final IndexedProperty indexedProperty) {
          final List<FieldValue> fieldValues = new ArrayList<FieldValue>();
          final Collection<String> fieldNames = fieldNameProvider.getFieldNames(
                  indexedProperty, null);
          for (final String fieldName : fieldNames) {
              fieldValues.add(new FieldValue(fieldName, newAttribute));
          }
          return fieldValues;
      }
  
      
  
      @Required
      public void setFieldNameProvider(final FieldNameProvider fieldNameProvider) {
          this.fieldNameProvider = fieldNameProvider;
      }
  }

Step : 3 Need to add query on which attribute you want to search new index type. Add this code to make search query for code and name or you can customize as you want

  yourcore-spring.xml
  
  <alias name="yourCommerceSearchTextPopulator" alias="yourCommerceSearchTextPopulator" />
      <bean id="yourCommerceSearchTextPopulator"
          class="com.core.search.solrfacetsearch.populators.YourSearchTextPopulator">
          <property name="freeTextQueryBuilders">
              <list>
                  <bean
                      class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                      <property name="propertyName" value="code" />
                      <property name="boost" value="90" />
                  </bean>
                  <bean
                      class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                      <property name="propertyName" value="name" />
                      <property name="boost" value="50" />
                  </bean>
              </list>
          </property>
      </bean>

Step: 4 Write controller , facade, service, converter and populator. So from controller you need to write new flow for searching and getting the result from solr. So just refer current flow of product search and implement new flow. So you need some populator and converter as well. Refer these OOTB files DefaultSolrProductSearchFacade,DefaultSolrProductSearchService etc.

Hope this will help you so pls accept as answer and keep upvote. cheers!

0 Kudos

Hi Abhishek,

Thanks for the quick response. Category comes in the same product catalog, in my case the itemtype is new one which dont come under any catalog, so do i need to add catalog and catalog version attributes to the newly created Itemtype and then follow the steps which you have mentioned above?

Former Member
0 Kudos

It is just example, category is also an item type. So whatever is your item just follow the same. And it is upto you how you are managing catalog version. Wherever you want change just change the facade , service and other flow. Above code snippet will complete index part end to end. So once you will start implementation you will get it better.So dont worry about that just carry on.

If it helps you pls accept as answer and keep upvote as it helps other as well.

Answers (0)