Defining SOLR Synonyms within Sitecore
Mercury allows content editors to maintain the synonyms for the SOLR search engine inside the sitecore content tree. This feature is based on SOLR's ManagedSynonymFilterFactory
which is described here
Within Sitecore the synonyms can be configured using a set of templates
- /sitecore/templates/Mercury/Foundation/Catalog/Settings/Synonym Folder
- /sitecore/templates/Mercury/Foundation/Catalog/Settings/Synonym List
/sitecore/templates/Mercury/Foundation/Catalog/Settings/Synonym Group
One item based on the Synonym Folder template should be placed within the site content. The Synonym Folder can contain zero or more Synonym Lists and each Synonym List can contain zero or more Synony Groups.
Each Synonym List can be used separately in the SOLR schema. The List has a field 'Synonym list name' which corresponds to the 'managed' attribute in the SOLR schema file
<fieldType name="content_search" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory" /> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> <filter class="solr.LowerCaseFilterFactory" /> <!-- since wildcards and synonyms cannot be combined querytime we need to filter the synonyms at index time --> <filter class="solr.ManagedSynonymFilterFactory" managed="mercury" /> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory" /> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> <filter class="solr.LowerCaseFilterFactory" /> </analyzer> </fieldType>
In order for the synonyms to work with wildcards, make sure that synonyms are filtered during index, by adding the
type="index"
attribute on the index element.
This way a different list of synonyms can be used for diferent field types.
Within a synonym list the synonyms are created as synonym groups. Each synonym group has a multi line text field Synonyms
. Eeach line contains a word that will act as a bi-directional synonym for all the others in the same group.
Synchronization
The synonyms that are defined in Sitecore are synchronized from sitecore to SOLR when the index is rebuild. If an index is configured as a 'SwitchOnRebuild' index, the synonyms will be synchronized to the inactive core before it is re-indexed and will become active when the cores are switched as part of the rebuild process.