Introduction
A Solr core is basically an index of the text and fields found in documents. A single Solr instance can contain multiple "cores", which are separate from each other based on local criteria. Having multiple cores helps us to segregate the data. Commerce provides a set of cores by default. They are
A Solr core is basically an index of the text and fields found in documents. A single Solr instance can contain multiple "cores", which are separate from each other based on local criteria. Having multiple cores helps us to segregate the data. Commerce provides a set of cores by default. They are
- MC_10001_CatalogEntry_en_US
- MC_10001_CatalogEntry_Unstructured_en_US
- MC_10001_CatalogGroup_en_US
Say we want to index a different data. An example would be as below
In order to support recipes we want have a search term to recipes relationship. When a customer searches anything we show a list of recipe names which has that search term. When they click on one of the name we can make a call to an external system where recipe information is stored and retrieve the specific recipe and show it to the user. So you need the data in SOLR in the below fashion
SearchTerm Recipes
milk Mascarpone mango lassi, Ultimate breakfast smoothie
cheese Canadian cheddar melt, Night mac and cheese
chicken Chicken paprica, Spanish chicken
beef Beef Stroganoff, Swiss Sizzler
We will keep the external integration away for now. Our requirement is to store the recipe to search term mapping in SOLR. As this is no way related to catentry or catgroup we don't want to keep it in the above listed cores and hence we will create a new one.
Steps
1. Change the solr.xml
- This xml has the configurations of solr cores defined. Navigate to WCS_InstalDir/Search/solr/home and open solr.xml
- To define a new core add the below line to it. "instanceDir" is the name of the folder where the configuration files are present and "name" is the name of new core.
2. Create the instance directory
Every solr core must have a set of configuration files which will be there in the instance directory. Solr provides a default core. You make a copy of this core and name it according to the solr.xml. So I would make a copy of Default folder and will rename it as "Recipes"
3. Alter schema.xml
Schema.xml defines the solr schema for the specific core. In order to index a field we need to use either an OOB solr field or create a custom field type of ours. Below is an example
<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"
generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1"
catenateAll="1" splitOnCaseChange="1" splitOnNumerics="1" preserveOriginal="1" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"
generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0"
catenateAll="0" splitOnCaseChange="0" splitOnNumerics="1" preserveOriginal="0" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Also add the fields that we need to create in the schema.xml
<field name="searchterm" type="text_suggest" indexed="true" stored="true" omitNorms="true"/>
<field name="recipes" type="text_suggest" indexed="true" stored="true" omitNorms="true" />
4. Add the new core in extended wc-search.xml
Add the below line in the <_config:cores> tag
<_config:core catalog="0" indexName="Recipes" language="en_US" name="recipes" path="Recipes" serverName="AdvancedConfiguration_1" />
This has to be done on wc-search xml in Search and WC project.
5. Clean, build, Restart and publish. Hit the below url and you should be able to see new core up and running.
http://localhost/solr/recipes/select?q=*:*
Population of indexes in this custom SOLR core will be covered in the next blog