CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member799736
Discoverer
Introduction:- Solr in Hybris  is used to Store the data in Indexed or meaningful or arranged way, in solr data stores in the form of json so searching makes easy. It helps to make the searching faster and efficient so that our application can reduce it's time, because it holds the arranged or indexed data so while searching the products it helps to reduce the CPU time..

--> In this blog post we are going to learn about solr indexing and ValueResolver/Provider.

Here Some Importent Questions are given,which are listed below:-

Q1) Why we are using Provider/Resolver?

ans:- We are fetching data from Hybris Database and inserting it to the Solr, if we want to do some modification on data in between fetching from Hybris Database and inserting into solr. So for this we are using Provider/Resolver Otherwise there is no need of using it.

Q2 When to use Provider and when to use Resolver?

ans:- ValueProveder is now depricated from Hybris version 5.5 onwards, so it is recommanded to create own class and extend AbstractValueResolver class and and Override addFieldValues() method.

 

For index or arrange the data in solr, we have to do indexing of the product.

In Solr three types of Indexing are there which are listed below:

(I) Full Indexing

(II)Update Indexing

(III)Delete Indexing

(I) Full Indexing :- In this strategy of indexing firstly it deletes all the Indexed documents and after that it will  do freshly indexing from the scratch. In Full Indexing 2 modes are there....

  • Direct Mode :- While using this mode of Full Indexing if error occurs and indexing fails than  lastly committed data will be available.

  • Two Phase Mode :- While using this mode of Full Indexing if error occurs and indexing fails than data will be rolled back to it's initial stage.


(II) Update Indexing :- In this strategy of indexing only new or modified documents will come under indexing.. It consumes less time compare than Full Indexing.

(III) Delete Indexing :- In this strategy of indexing it used to remove indexed data.....It is used to maintain the consistency of indexed data as we might have Unwanted Indexed Data in solr from a long time.

 

Indexing can be done in two ways

(I) Trough impex (Best Way)

(II) Through HAC

So in this post we are going to learn Indexing through impex

 

Below is given one example's steps to use a Resolver,

 

Requirement:- Display the Unit of products with it. for example if user is searching the cup than it should be displays with it's unit that is dozen similerly if user is searching t-shirt so i should be display with it's unit that is piece..

 


in the above product unit of the product is not displaying, now will follow some of the steps to display unit of product


 

Step1 :- create a class in com.nt.core.search.solrfacetsearch.provider.impl Package and extend AbstractValueResolver class and write here modification logic.

eg-:
package com.nt.core.search.solrfacetsearch.provider.impl;
public class SolrUnitDisplay extends AbstractValueResolver<ProductModel, Object, Object>
{
private CommonI18NService commonI18NService; private UserService userService;
@Override
protected void addFieldValues(InputDocument inputDocument, IndexerBatchContext
indexerBatchContext, IndexedProperty indexedProperty,
ProductModel productModel, ValueResolverContext<Object, Object>
valueResolverContext) throws FieldValueProviderException
{
LanguageModel languageModel = getCommonI18NService().getCurrentLanguage();
String UnitName = getUnitName(productModel,languageModel);
if (UnitName!=null) inputDocument.addField(indexedProperty,UnitName);
}
}

 

Step - 2:- Build the project by using ant all.

 

Step - 3:- :- Create bean id for SolrUnitDisplay class in trainingcore.resources.trainingcore-spring.xml file.

eg-:
<bean id="solrUnitDisplay"
class="com.nt.core.search.solrfacetsearch.provider.impl.SolrUnitDisplay" parent="abstractValueResolver">
<property name="commonI18NService" ref="commonI18NService"/>
<property name="userService" ref="userService"/>
</bean>

Step- 4 :- Create an impex and declare bean id of Resolver class on that impex as below...
eg-:


$productCatalog=apparelProductCatalog 
$catalogVersions=catalogVersions(catalog(id),version);
$facetSearchConfigName=apparel-ukIndex
$facetSearchConfigDescription=Apparel UK Solr Index
$searchIndexNamePrefix=apparel-uk
$solrIndexedType=apparel-ukProductType
$indexBaseSite=apparel-uk
$indexLanguages=en
$indexCurrencies=GBP
INSERT_UPDATE SolrIndexedProperty ;solrIndexedType(identifier [unique=true];name[unique=true];type(code);localized[default=false];fieldValueProvider
;$solrIndexedType ;unit ;string ;true ;solrUnitDisplay


 

Step - 5:- Build the project by using ant all.

 

Step - 6:- Do the Server up using "Hybrisserver.bat" command.

 

step - 7:- Open the apparel site and see the below given outputs

 

Here is given the unit of the product with products, here we have searched for t-shirt so it's unit *piece* is displaying with the product.




CONCLUSION:-

This is how we can create and use SOLR and AbstractValueResolver as well.




If you have any query related to Solr you can ask by commenting here.
1 Comment