Solr configuration in Hybris
In Hybris, Solr configuration is out-of-box and it is using impex files for manage the configuration in Hybris .
Below are impex files for related to Solr.
solr.impex
solr.impex file contains the configuration of Solr server, indexing types , facets etc. It is exist on below path
/import/coredata/stores/hybris/solr.impex
Create Solr server configuration
SolrServerConfig table is used to manage for solr server configuration name and mode of the server to indicate whether it’s embedded or standalone server. we will insert data in table based of mode of server.
$serverConfigName=expertshybrisSolrServerConfig
//embedded
INSERT_UPDATE SolrServerConfig;name[unique=true];mode(code);embeddedMaster
;$serverConfigName;embedded;true
------------------------------------------------------------------------------------------------------------------------------------------
//standalone
;$serverConfigName;standalone ;false
For standalone solr server configuration , we need insert data to SolrEndpointUrl table .It means actual URL on which solr is running.
INSERT_UPDATE SolrEndpointUrl;solrServerConfig(name)[unique=true];url[unique=true]; master[unique=true,default=false]
;$serverConfigName;standalone;http://localhost:8983/solr;true
Create Solr indexer configuration
$indexConfigName=expertshybrisSolrIndexConfig
INSERT_UPDATE SolrIndexConfig;name[unique=true];batchSize;numberOfThreads;indexMode(code);
;$indexConfigName;100;1;TWO_PHASE;
Create the faceted search configuration
$searchConfigName=expertshybrisPageSize
INSERT_UPDATE SolrSearchConfig;description[unique=true];pageSize
;$searchConfigName;20
Declare the indexed type Product
Below impex is used for define the hybris item types to be indexed in the SolrIndexedType
$solrIndexedType=expertshybrisProductType
INSERT_UPDATE SolrIndexedType;identifier[unique=true];type(code);variant;sorts(&sortRefID)
;$solrIndexedType;Product;false;sortRef3,sortRef4,sortRef5,sortRef6
Define Facet Search Config
Faceting is the arrangement of search results into categories based on indexed terms. We need to define below impex for SolrFacetSearchConfig which is associate to solrServerConfig, solrSearchConfig, solrIndexConfig, solrIndexedTypes & Product catalog etc.
$facetSearchConfigName=expertshybrisIndex
$facetSearchConfigDescription=Experts Hybris Index
$searchIndexNamePrefix=expertshybris
$indexBaseSite=expertshybris
$indexLanguages=en
$indexCurrencies=USD
$serverConfigName=expertshybrisSolrServerConfig
$indexConfigName=expertshybrisSolrIndexConfig
$solrIndexedType=expertshybrisProductType
$productCatalog=expertshybrisProductCatalog
$catalogVersions=catalogVersions(catalog(id),version);
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;true;$productCatalog:Online,$productCatalog:Staged
Associate solr to website
Below impex is used for link to website
$indexBaseSite=expertshybris
$facetSearchConfigName=expertshybrisIndex
UPDATE BaseSite;uid[unique=true];solrFacetSearchConfiguration(name)
;$indexBaseSite;$facetSearchConfigName
Defining the range value set
you have seen in commerce website where price range facet which help to search product based on price range. which can create with help to solr range value set. Below impex is used to define value range set. We will insert value in SolrValueRangeSet & SolrValueRange table. Both impex is associated with each other.
INSERT_UPDATE SolrValueRangeSet;name[unique=true];qualifier;type;solrValueRanges(&rangeValueRefID)
;expertshybrisPriceRangeUSD;USD;double;rangeRefUSD1,rangeRefUSD,rangeRefUSD,rangeRefUSD4,rangeRefUSD5,rangeRefUSD6
# Define price ranges
INSERT_UPDATE SolrValueRange;&rangeValueRefID;solrValueRangeSet(name)[unique=true]; name[unique=true]; from;to
;rangeRefUSD1;expertshybrisPriceRangeUSD; $0-$49.99; 0; 49.99
;rangeRefUSD2;expertshybrisPriceRangeUSD; $50-$199.99; 50; 199.99
;rangeRefUSD3;expertshybrisPriceRangeUSD; $200-$499.99; 200; 499.99
;rangeRefUSD4;expertshybrisPriceRangeUSD; $500-$999.99; 500; 999.99
;rangeRefUSD5;expertshybrisPriceRangeUSD; $1,000-$99,999.99;1000; 99999.99
;rangeRefUSD6;expertshybrisPriceRangeUSD; $100,000-more; 100000;
Define the non-facet indexed
Non-Facet is the arrangement of search based indexed properties but not part of facet. When we make many property value searchable then we have required to index properties in solr. which make fast search on website. We need to define different features for each property on how it should be indexed, We also need to define the Value provider for some of the attributes whose value cannot be understood by Solr directly. Value provide has help to provide value as per solr required.
$solrIndexedType=expertshybrisProductType
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;ftsPhraseQuery[default=false];ftsPhraseQueryBoost;ftsQuery[default=false];ftsQueryBoost;ftsFuzzyQuery[default=false];ftsFuzzyQueryBoost;ftsWildcardQuery[default=false];ftsWildcardQueryType(code)[default=POSTFIX]; ftsWildcardQueryBoost;ftsWildcardQueryMinTermLength
;$solrIndexedType; itemtype ;string ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
;$solrIndexedType; code ;string ; ; ; ; ;true;true;springELValueProvider ;code; ; ;true;90 ; ; ;true;POSTFIX;45;3
;$solrIndexedType; name ;text ;sortabletext; ;true; ;true;true;springELValueProvider ;getName(#lang); true;100; true;50;true;25; ; ; ;
;$solrIndexedType; priceValue;double ; ;true; ; ; ; ;volumeAwareProductPriceValueProvider ; ; ; ; ; ; ; ; ; ; ;
Define the Facet indexed
Facet is the arrangement of search results into categories based on indexed terms. Facet properties are generally displayed at the top or side of the site where we can select those facet fields to get the filter products accordingly. we have to defined facet[default=true] to indicate that the field is facet type
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; price ;double ; ;true;;; ;MultiSelectOr ;Alpha ; 4000;true;; ;volumeAwareProductPriceValueProvider ;; ;defaultTopValuesProvider ;priceRangeUSD
;$solrIndexedType; brandName ;text ;true;;; ; ;brandCategoryNameValueProvider; ; ; ; ; ;
Define indexed queries
we need to define the queries that will be used to extract data for Solr. we will define indexed queries for full index and update index.
INSERT_UPDATE SolrIndexerQuery;solrIndexedType(identifier)[unique=true];identifier[unique=true];type(code);injectCurrentDate[default=true];injectCurrentTime[default=true];injectLastIndexTime[default=true];query;user(uid);$solrIndexedType;$solrIndexedType-
fullQuery;full;;;false;"SELECT {PK} FROM {Product}";anonymous;$solrIndexedType;$solrIndexedType-updateQuery;update;;;;"SELECT {p:PK} FROM {Product AS p} WHERE ({p:modifiedtime} >= ?lastIndexTime";anonymous
Full index query: This query get all product data.
Update index query: This quey get only those product which are update after last (full or last) index
Define the sorts
Below impexes are used for define sorting. one impex have reference of second impex.
INSERT_UPDATE SolrSort;&sortRefID;indexedType(identifier)[unique=true];code[unique=true];useBoost
;sortRef1;$solrIndexedType;relevance;true
;sortRef2;$solrIndexedType;topRated;false
# Define the sort fields
INSERT_UPDATE SolrSortField;sort(indexedType(identifier),code)[unique=true];fieldName[unique=true]; ascending[unique=true]
;$solrIndexedType:relevance;inStockFlag;false
;$solrIndexedType:relevance;score;false
solr_en.impex
This impex file is used for localization of solr indexed fields in English language as below
/import/coredata/stores/hybris/solr_en.impex
Similarly for other languages we will have corresponding solr localization files in the appropriate localization folders.
$lang=en
UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true]; displayName[lang=$lang]
;$solrIndexedType;Colour of product;"Colour"
solrtrigger.impex
This impex file is used to schedule the cron jobs for Solr indexing.
import/coredata/stores/hybris/solrtrigger.impex
In general terms , We scheduleded full indexing job in once a day and update indexing is scheduled to run every 2 hrs.
INSERT_UPDATE Trigger ; cronJob(code)[unique=true] ; second ; minute ; hour ; day ; month ; year ; relative ; active ; maxAcceptableDelay
# Run the full-expertshybrisIndex-cronJob at 4:05 AM every day
; full-expertshybrisIndex-cronJob ; 0 ; 5 ; 4 ; -1 ; -1 ; -1 ; false ; false ; -1
# Run the update-expertshybrisIndex-cronJob every 2 hours
; update-expertshybrisIndex-cronJob ; 0 ; 0 ; 2 ; -1 ; -1 ; -1 ; true ; false ; -1