11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway ABOUT AUTHOR SUBSCRIBE US (HTTP://JAVAINSIMPLEWAY.COM/SUBSCRIBE-US/)
Menu
(http://javainsimpleway.com/)
.COM Domain at Just ₹99
Search
.COM Domain at Just ₹99
Solr in Hybris Solr Overview in Hybris (http://javainsimpleway.com/solr-overview-in-h (http://javainsimpleway.com/solr-overview-in-hybris/) ybris/) Understanding Solr conguration in Hybris (htt p://javainsimpleway.com/understanding-solr-con p://javainsimpleway.com/understanding-solr-conguration-in-hybris/) guration-in-hybris/) Solr Indexing wit h basic attribute (http://javainsimpleway.com/solr-indexing-with-basic-attribute/) Value provider in Hybris Solr – Overview (http://javainsimpleway.com/value-provider-in-hybris-solr-overview/) (http://javainsimpleway.com/value-provider-in-hybris-solr-overview/) Value Value Provider in Solr with example (http://javainsimpleway.com/value-provider-in-solr-with-example/) (http://javainsimpleway.com/value-provider-in-solr-with-example/)
Hybris Hybris WCMS WCMS Overview (http://javainsimpleway.com/wcms-overview/) Adding CMS component in Hybris (http://javainsimpleway.com/adding-new-cms-component/) (http://javainsimpleway.com/adding-new-cms-component/) Adding Custom CMS component in Hybris (http://javainsimpleway.com/how-to-add-new(http://javainsimpleway.com/how-to-add-new-custom-cms-component-type-to-a-pa custom-cms-component-type-to-a-page-in-hybris/) ge-in-hybris/) Creating new page in Hybris (http://javainsimpleway.com/creating-new-page-in-hybris/) (http://javainsimpleway.com/creating-new-page-in-hybris/)
Understanding Solr configuration in Hybris
In Hybris, we have to configure the Solr in impex files Lets see the impex files used for the same in detail 1)solr.impex /import/coredata/stores/hybris/solr.impex 2)solr_en.impex /import/coredata/stores/hybris/solr_en.impex 3)solrtrigger.impex import/coredata/stores/hybris/solrtrigger.impex
1)solr.impex This le contains all the conguration of So lr including Solr server,indexing types,facets etc. types,facets etc. Note: All Note: All the variables in the below impex les which starts with $ are called as macros and macros and should be dened at the beginning of the impex.
Solr server configuration We need to insert the data to SolrServerCong table SolrServerCong table with solr server conguration name and name and mode of mode of the server to indicate whether it’s embedded or embedded or standalone server. Below impex line will do this 1 2
INSERT_UPDATE INSERT_UPDATE SolrServerCong;name[unique= SolrServerCong;name[unique=true true];mode(code);embeddedMaster ];mode(code);embeddedMaster ;$serverCongName;embedded;true true
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
1/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
We have congured solr server to be embedded.
Menu
If we want to make solr server as standalone then we have to insert below data to SolrServerCong table 1 2
INSERT_UPDATE SolrServerCong;name[unique=true];mode(code);embeddedMaster ;$serverCongName;standalone;false; Search
For standalone solr server conguration , we must insert data to SolrEndpointUrl table as well to indicate the actual url where solr is running. 1 2
INSERT_UPDATE SolrEndpointUrl;solrServerCong(name)[unique=true];url[unique=true];master[unique=true,default=false] ;$serverCongName;http://localhost:8983/solr;true
solr indexer configuration we need to insert the data to SolrIndexCong table with index conguration name,batch size of indexing,number of threads to run and the index mode 1 2
INSERT_UPDATE SolrIndexCong;name[unique=true];batchSize;numberOfThreads;indexMode(code); ;$indexCongName;100;1;TWO_PHASE;
We have dened the batch size to be 100 1 thread for processing index and TWO_PHASE as the indexing strategy. Check Solr overview in Hybris (http://javainsimpleway.com/solr-overview-in-hybris/) article for the details of TWO_PHASE indexing mode.
Solr search configuration we need to insert the data to SolrSearchCong table with page size and description 1 2
INSERT_UPDATE SolrSearchCong;description[unique=true];pageSize ;$searchCongName;20
We have given the page size as 20, so 20 pages of results will be retrieved by Solr.
Define the Solr indexed Types We need to dene the hybris item types to be indexed in the SolrIndexedType table 1 2
INSERT_UPDATE SolrIndexedType;identier[unique=true];type(code);variant;sorts(&sortRefID) ;$solrIndexedType;Product;false;sortRef1,sortRef2,sortRef3,sortRef4,sortRef5,sortRef6
We have dened only one hybris item type to be indexed which is Product Type and dened some of the sorting references which we will dene in the subsequent impex below.
Solr Facet Search Config We need to insert the data to SolrFacetSearchCong table to dene index name prex,supporting languages,currencies and also link the solrServerCong, solrSearchCong, solrIndexCong, solrIndexedTypes dened above. We also need to dene the fallback language and catalog version 1 2
INSERT_UPDATE SolrFacetSearchCong;name[unique=true];description;indexNamePrex;languages(isocode);currencies(isocode);solrServerCong(name);solrSearchCong( ;$facetSearchCongName;$facetSearchCongDescription;$searchIndexNamePrex;$indexLanguages;$indexCurrencies;$serverCongName;$searchCongName;$indexCon
Link the solr to the site We need to link the solr conguration to the site by providing solrFacetSearchConguration to the Base site as below 1 2
UPDATE BaseSite;uid[unique=true];solrFacetSearchConguration(name) ;$indexBaseSite;$facetSearchCongName
Defining the range value set We need to insert the data to SolrValueRangeSet table for dening the Solr value range references which we will dene in the next impex. 1 2
INSERT_UPDATE SolrValueRangeSet;name[unique=true];qualier;type;solrValueRanges(&rangeValueRefID) ;priceRangeGBP;GBP;double;rangeRefGBP1,rangeRefGBP2,rangeRefGBP3,rangeRefGBP4,rangeRefGBP5
We have dened 5 ranges for priceRangeGBP and we will dene the values for the same in the below impex
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
2/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
We need to insert the data for SolrValueRange table to dene the actual range values for each range reference as below 1 2 3 4 5 6
Menu
INSERT_UPDATE SolrValueRange;&rangeValueRefID;solrValueRangeSet(name)[unique=true];name[unique=true];from;to ;rangeRefGBP1 ;priceRangeGBP;£0-£19.99; 0; 19.99 ;rangeRefGBP2 ;priceRangeGBP;£20-£49.99; 20; 49.99 ;rangeRefGBP3 ;priceRangeGBP;£50-£99.99; 50; 99.99 Search ;rangeRefGBP4 ;priceRangeGBP;£100-£199.99; 100;199.99 ;rangeRefGBP5 ;priceRangeGBP;£200-£299.99; 200;299.99
we will use priceRangeGBP to provide range for the indexed property while dening indexed property.
Defining the non-facet indexed properties We need to insert the data into SolrIndexedProperty table for dening the properties of item types to be indexed. We need to dene dierent features for each property on how it should be indexed, whether it has to be multivalued,used for autocomplete etc. 1 2 3
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[defau ;$solrIndexedType; name ;text ;sortabletext; ;true; ;true;true; ;$solrIndexedType; priceValue ;double ; ;true; ; ; ; ;productPriceValueProvider;
We also need to dene the Value provider for some of the attributes whose value cannot be understood by Solr directly. We will see how value providers works in a separate article.
Defining the Facet indexed properties Facet properties are generally displayed at the sidebar of the site where we can select those facet elds to get the list of products accordingly.
.COM Domain at Just ₹99. Register Your Domain Name Before it's Taken. Secure The Domain Name You Want Before it's Taken. Buy Now! Ad
BigRock Learn More 1 2
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[defau ;$solrIndexedType; price ;double ; ;true ; ; ; ;MultiSelectOr ;Alpha ; 4000;true; ; ;productPriceValueProvider ; ; ;d
We have dened price eld as facet eld and it can be selected to lter the products based on that eld. we have dened facet[default=true] to indcate that the eld is facet type
Define the indexed queries We need to dene the indexed queries for full index and update index so that solr picks up the corresponding source data from hybris for indexing. 1 2 3
INSERT_UPDATE SolrIndexerQuery;solrIndexedType(identier)[unique=true];identier[unique=true];type(code);injectCurrentDate[default=true];injectCurrentTime[default ;$solrIndexedType;$solrIndexedType-fullQuery;full;;;false;"SELECT {PK} FROM {Product}";anonymous ;$solrIndexedType;$solrIndexedType-updateQuery;update;;;;"SELECT {p:PK} FROM {Product AS p} WHERE ({p:modiedtime} >= ?lastIndexTime";anonymous
We have dened the 2 queries that Solr uses for full indexing and update indexing. Full indexing query gets all the data without any condition Update indexing query gets the data which has been modied from the last indexed time, so it won’t fetch entire data for indexing and hence it’s faster too.
Defining the Sort We need to insert the sort references into SolrSort table which we will be using while inserting values for SolrIndexedType to dene the sorts for the indexed item type 1 2 3 4 5 6 7
INSERT_UPDATE SolrSort;&sortRefID;indexedType(identier)[unique=true];code[unique=true];useBoost ;sortRef1;$solrIndexedType;relevance;true ;sortRef2;$solrIndexedType;topRated;false ;sortRef3;$solrIndexedType;name-asc;false ;sortRef4;$solrIndexedType;name-desc;false ;sortRef5;$solrIndexedType;price-asc;false ;sortRef6;$solrIndexedType;price-desc;false
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
3/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
we have given these references while inserting data into SolrIndexedType table above.
Menu
Define the Solr sort fields We need to insert the sorting elds into SolrSortField table which will be linked to the sort reference codes dened above
Search 1 2 3 4 5 6 7 8 9
INSERT_UPDATE SolrSortField;sort(indexedType(identier),code)[unique=true];eldName[unique=true];ascending[unique=true] ;$solrIndexedType:relevance;inStockFlag;false ;$solrIndexedType:relevance;score;false ;$solrIndexedType:topRated;inStockFlag;false ;$solrIndexedType:topRated;reviewAvgRating;false ;$solrIndexedType:name-asc;name;true ;$solrIndexedType:name-desc;name;false ;$solrIndexedType:price-asc;priceValue;true ;$solrIndexedType:price-desc;priceValue;false
We have dened 5 sort elds as below inStockFlag eld can be sorted based on relevance and Top rating in descending order. score eld can be sorted based on relevance only in descending order reviewAvgRating eld can be sorted based on Top rating only in descending order name eld can be sorted based on both ascending & descending order price eld can be sorted based on both ascending & descending order
2)solr_en.impex import/coredata/stores/apparel-uk/solr_en.impex This impex le is used for localization of solr indexed elds in English language as below 1 2 3 4
UPDATE SolrIndexedProperty;solrIndexedType(identier)[unique=true];name[unique=true];displayName[lang=$lang] ;$solrIndexedType;allPromotions;"Promotions" UPDATE SolrSort;indexedType(identier)[unique=true];code[unique=true];name[lang=$lang] ;$solrIndexedType;name-asc;"Name (ascending)"
Similarly for other languages we will have corresponding solr localization les in the appropriate localization folders.
3)solrtrigger.impex /import/coredata/stores/apparel-uk/solrtrigger.impex This impex le is used to schedule the cron jobs for Solr indexing. 1 2 3 4 5 6
INSERT_UPDATE Trigger; cronJob(code)[unique=true];second;minute;hour;day;month;year;relative;active;maxAcceptableDelay # Run the full index cronJob at 3:05 AM every day ;full-index-cronJob;0;5;3;-1;-1;-1;false;false;-1 # Run the update index cronJob every 1 minutes ;update-index-cronJob;0;1;-1;-1;-1;-1;true;false;-1
We have dened cron job scheduling time through Trigger table for both full and update indexing. We can observe that full indexing job is scheduled only once a day and update indexing is scheduled to run every 1 minute. we already know the reason why update index runs more frequently, if not please check Solr overview in Hybris (http://javainsimpleway.com/solr-overview-inhybris/) article For practicing in B2C Apparel store, check the below impex le hybris\bin\ext-data\apparelstore\resources\apparelstore\import\coredata\stores\apparel-uk\solr.impex
About the Author http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
4/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
Karibasappa G C (KB) (http://javainsimpleway.com/author/karibasappagc/)
Menu
Founder of javainsimpleway.com (http://javainsimpleway.com) I love Java and open source technologies and very much passionate about software development. I like to share my knowledge with others especially on technology I have given all the examples as simple as possible to understand for the beginners. Search All the code posted on my blog is developed,compiled and tested in my development environment. If you nd any mistakes or bugs, Please drop an email to
[email protected] Connect with me on Facebook (http://www.facebook.com/javainsimpleway) for more updates
Atos SAP Training Unlimited Placement Calls Ad sapeducation.atos.net
Creating new page in Hybris avainsimpleway.com
Solr Indexing with basic Defining Relation in attribute items.xml in Hybris avainsimpleway.com
avainsimpleway.com
Defining Enum and Map Adding Custom CMS types in Hybris component in Hybris
WCMS Overview
avainsimpleway.com
avainsimpleway.com
avainsimpleway.com
Collection v/s relation in Hybris avainsimpleway.com
Share this article on (/#facebook)
(/#twitter)
(/#google_plus)
(/#linkedin)
(/#whatsapp)
(https://www.addtoany.com/share#url=http%3A%2F%2Fjavainsimpleway.com%2Funderstanding-solr-conguration-inhybris%2F&title=Understanding%20Solr%20conguration%20in%20Hybris)
<
Prev (http://javainsimpleway.com/solr-overview-in-hybris/) Next (http://javainsimpleway.com/solr-indexing-with-basic-attribute/)
>
Comment (20)
Vitaliy July 30, 2017 at 2:21 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-112925)
Hi KB, here is the following impex INSERT_UPDATE SolrSort;&sortRefID;indexedType(identier)[unique=true];code[unique=true];useBoost ;sortRef1;$solrIndexedType;relevance;true ;sortRef3;$solrIndexedType;name-asc;true
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
5/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
;sortRef4;$solrIndexedType;name-desc;true
Menu
;sortRef5;$solrIndexedType;price-asc;true
;sortRef6;$solrIndexedType;price-desc;true when I set useBoost=true for name-asc, name-desc, price-asc, price-desc and relevance – the products are sorted in the same order for all of these types of
Search
sorting
I have no boost rules dened for products… so why name and price are not sorted when useBoost=true ? Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=112925#respond)
Prakash June 26, 2017 at 5:44 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-112746)
Hi KB, In which scenario we will go through embedded mode and for which scenario we will go through standalone mode.Could you please claried it. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=112746#respond)
Cli March 31, 2017 at 5:47 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111540)
Nice article! However, I have encountered an issue with items getting indexed. On my end, it gets all the items regardless of the CatalogVersion even if we specify the it in the Facet Search Cong. Do you have any idea on this? Thank you! Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111540#respond)
Rajesh Singh February 10, 2017 at 7:14 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111073)
Hi Karibasappa, I have some confusion in Solr and i’m new to Solr can you provide the you contact number. Thanks Rajesh Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111073#respond)
Sandeep February 10, 2017 at 6:25 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111071)
Why do we need to dene sort. Can you explain that in realtime where we need it by example. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111071#respond)
Karibasappa G C (KB)
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
6/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway February 10, 2017 at 5:59 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111075)
Menu
We need to dene the sort elds if we are providing the Sort functionality to the user on some elds while searching for a product. Example:
Search You can sort products based on its Popularity or based on its price
If you open jabong or ipkart site, You can see this Sort By option to sort the products. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111075#respond)
Ramsandeep February 13, 2017 at 7:21 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111094)
Thank you for help, there is paramater in SolrSort useBoost – can you explain why we need it. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111094#respond)
Ramsandeep February 13, 2017 at 8:43 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111095)
INSERT_UPDATE SolrIndexCong;name[unique=true];batchSize;numberOfThreads;indexMode(code);legacyMode ;$indexCongName;100;1;TWO_PHASE;false Hi, what is the good cong for – numberOfThreads in your experience Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111095#respond)
Karibasappa G C (KB) February 13, 2017 at 6:29 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111102)
Boost will help Solr to consider it more important while searching. Its like Google Page Rank on the documents search. There are 2 kinds of boosts. Index-time and Query-time boosts. Index-time boosts are applied when adding documents, and apply to the entire document or to specic elds. Query-time boosts are applied when constructing a search query, and apply to specic elds. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111102#respond)
Ramsandeep February 14, 2017 at 5:43 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111107)
Thanks KB. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111107#respond)
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
7/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
Menu
Search
Sai January 6, 2017 at 10:16 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110777)
Hi KB, To add to my previous question, another question related impex syntax INSERT_UPDATE SolrIndexedType;identier[unique=true];type(code);variant;sorts(&sortRefID) ;$solrIndexedType;Product;false;sortRef1,sortRef2,sortRef3,sortRef4,sortRef5,sortRef6 what does the ‘&’ symbol and its signicance here Thanks Sai Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110777#respond)
Karibasappa G C (KB) January 6, 2017 at 4:26 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110781)
Hi Sai, “&” is used to dene “PartOf” attri butes in impex, its also called Document Id , which is used to reference the att ributes dened in the same impex only. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110781#respond)
Sai January 6, 2017 at 10:08 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110776)
Hi KB, Your explanation is very interesting. I have a query here that what does batchsize in solr indexer and it dier from pagesize?? Generally what would be the prefered number o f threads conguration for solr indexer in dierent environments ?? Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110776#respond)
Karibasappa G C (KB) January 6, 2017 at 4:17 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110780)
Hi Sai, Thank you!! Batchsize species how many records solr can process at a time when it gets from actual DB for indexing… If records are huge then batch size helps Solr to process it batch by batch.
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
8/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway Page size species how many pages of data can be retrieved by Solr.
Menu
Example: If batch size is 100 and page size is 20 it means each page it can retrieve 100 records..
Search Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110780#respond)
Hamid March 1, 2017 at 10:04 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111239)
simply awesome explanation Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111239#respond)
Karibasappa G C (KB) March 1, 2017 at 2:20 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-111240)
Thank you!! Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=111240#respond)
Prem December 29, 2016 at 11:10 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110708)
Great article on Solr and hybris integration! Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110708#respond)
Karibasappa G C (KB) December 29, 2016 at 12:46 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110709)
Thank you Prem !! Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110709#respond)
Somdip Sanyal December 26, 2016 at 9:07 pm (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110686)
Great article really helped me a lot . Keep it up. Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110686#respond)
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
9/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
Menu
Karibasappa G C (KB) December 27, 2016 at 10:35 am (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/#comment-110690)
Search
Thank you Somdip !!
Reply (http://javainsimpleway.com/understanding-solr-conguration-in-hybris/?replytocom=110690#respond)
Leave a Comment Message
Name*
Email*
Phone
Please answer this simple challenge to post your valuable comment * seven + six =
Post Comment
(https://www.facebook.com/javainsimpleway/)
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
10/11
11/15/2017
Understanding Solr configuration in Hybris | Javainsimpleway
Menu
Search
Click Here
http://javainsimpleway.com/understanding-solr-configuration-in-hybris/
11/11