Synonyms #
The synonyms feature allows you to define search terms that should be considered equivalent. For example, when you define a synonym for sneaker as shoe, searching for sneaker will now return all records with the word shoe in them, in addition to records with the word sneaker.
Typesense supports two types of synonyms:
-
One-way synonyms: This is where you define a “root” word that is used in place of other terms. For example, if a user searches for smart phone, it will be treated as a synonym for iphone or android. Defining the words iphone and android as one-way synonyms of smart phone will cause searches for smart phone to return documents containing iphone or android or both. However, searches for android will not return documents containing iphone or smart phone because the relationship is one way.
-
Multi-way synonyms: Defining the words blazer, coat and jacket without a root word treats the set as multi-way synonyms. This means all three words can be used interchangeably with each other. This will cause searches for any one of those words (eg: coat) to return documents containing at least one of the words in the synonym set (eg: records with blazer or coat or jacket are returned).
CMS Setup #
All collections in the CMS have a Synonyms tab for manipulating synonyms. When they are added, edited, or deleted in the CMS, they are automatically updated or removed on the Typesense server. They are not synced, so if deleted on the remote server first, the synonyms in the CMS will not be correct - if you save the set again, it will then update and restore it on the server.
When creating a synonynm for the first time, you need to provide it with a unique ID. If the field is left empty, a random one will be generated and it cannot be changed later.
- To create a one-way synonym, enter a root word, then a synonym set in the multivalue field provided
- To create a multi-way synonym, leave the root word field blank. The synonym set entered into the multivalue field means all of those words are interchangeable with one another.
- If you are working with non-English languages that use different alphabets, change the Locale setting to one of the provided values. If you are sure, leave the field alone as English to let Typesense process with its default settings.
- By default, special characters are dropped from synonyms. Use the symbols_to_index attribute to specify which special characters should be indexed as is. You’ll want to provide these characters when you know your synonyms contains symbols, such as
C++
,C#
, orASP.NET
.
Note: symbols_to_index and locale values are not shown in the Typesense Dashboard. An issue has been created for this here.