Table of Contents

Synonyms

Step-by-Step guide to implement Synonyms in the search function

Incorporating synonyms into the search function makes it more robust, user-friendly and effective at delivering relevant results, ultimately enhancing the overall user experience.

This step-by-step guide will demonstrate how to incorporate synonyms into the search function, using the products repositories as an example.

First, we need to create a field type, which uses the SynonymAnalyzer:

  1. Go to the index where you want to implement the synonyms feature, in this example it is Settings/Repositories/SwiftProducts/Products
  2. Click the context menu in the Index fields section and select "Manage field types" Index field
  3. Click the "+ New field type" button
  4. Provide the field type with a name, e.g. WithSynonyms
  5. Set the type to System.String
  6. Select the SynonymAnalyzer
  7. Save and close Fieldtype settings

Now, we need to add a field of this type to the index containing the data we want to match to the synonyms - In this example we will use the long description, but it can be applied to other types as well.

  1. Click the context menu in the Index fields section and select "Manage fields"
  2. Click "+ New index field" in the upper right corner and select "Field"
  3. Provide the field with a name, e.g. Long description with synonyms
  4. In the Field section, select the type you created before, in this case WithSynonyms
  5. Remember to check Indexed and Analyzed
  6. Set source to ProductLongDescription
  7. Save and close

Long description with synonyms

The next step is to go to Assets/System/Repositories/{NameOfYourRepository} and create two files:

  • A config file which handles what analyzers to use
  • An xml file containing a list of synonyms

NB: Both files must be named bases on the system name of the field type you created previously – in this case WithSynonyms.config and WithSynonyms_synonyms.xml

Examples of both files are shows below:

WithSynonym.config:

<?xml version="1.0" encoding="utf-8" ?>
<SynonymAnalyzer>
  <TokenizerType>
    LowerCase
  </TokenizerType>
  <StemmerName>
    English
  </StemmerName>
  <StopWords>
  </StopWords>
</SynonymAnalyzer>

WithSynonyms_synonyms.xml:

<synonyms>
<group stem="inch">
<synonym>inch</synonym>
<synonym>in.</synonym>
<synonym>inches</synonym>
</group>
<group stem="fast">
<synonym>fast</synonym>
<synonym>quick</synonym>
<synonym>rapid</synonym>
<synonym>rapido</synonym>
</group>
<group stem="slow">
<synonym>slow</synonym>
<synonym>decrease</synonym>
</group>
<group stem="check">
<synonym>check</synonym>
<synonym>lookup</synonym>
<synonym>look</synonym>
</group>
<group stem="apk">
<synonym>armored personnel carrier</synonym>
</group>
</synonyms>

As given in the config file the TokenizerType is set to LowerCase. This means that you should ensure to keep the content of the XML file lower case.

Currently we do not supply any synonym lists out of the box, but you should be able to scrape data from an online source.

We now need to incorporate two query expressions based on the previously created field (Long description with synonyms) into the existing search section:

  1. Go to Settings/Repositories/SwiftProducts
  2. Click the Products.query in the Queries section Products queries
  3. Scroll down to the Expressions section and click "Manage"
  4. Find the group with the search expressions Search group
  5. Click the context menu and select "+ New expresssion"
  6. Set field to "Long description with synonyms"
  7. Select the "Equal" operator
  8. Select the "Parameter" type
  9. Set the Parameter to eq
  10. Save

For the other expression, follow the steps from 1-8, but select the q as the Parameter in step 9. The group should now look like this:

Expression added

Make sure you rebuild the index, and that you have products using the synonyms in your product catalog – searching for any of terms in the synonym file will now also return products using any of the other synonyms.

Rapid search

To top