Synonyms
On this page
Synonyms tell the engine which words and expressions should be considered equal - for example, pants ⇔ trousers
or mad ⇔ angry
.
A search for “trousers” will find “pants”, and “pants” will find “trousers”.
You can also create synonym groups.
For example, you can add “slacks” to the “pants, trousers” group: pants ⇔ trousers ⇔ slacks
.
In this case, a search for “slacks” finds “pants” and “trousers”, and “pants” finds “trousers” and “slacks”, and so on.
Finally, prefix search is also enabled on the synonym, so if your data includes “trousers”, and a user searches for pants, then searches for p
, pa
, pan
would show results for both “pants” and “trousers”.
While synonyms are powerful, sometimes they can lead to surprising or undesirable results. Accordingly, they should be used sparingly.
The different types of synonyms
Regular synonyms (default)
Synonyms are, by default, mutually equivalent; that is, each word signifies the other. “Pants” = “trousers” and “trousers” = “pants”. You can have groups. “Slacks” = “pants” = “trousers”.
Other types of synonyms
Algolia provides 3 other types of synonyms which can be useful in certain contexts:
1. One-way synonyms
Use this when you want a word or phrase to find its synonyms, but not the reverse.
For example, you want “tablet” to find “ipad”, so that iPads show up on all “tablet” searches. However, you don’t want the reverse: you don’t want an “ipad” search to find all tablets. For example, a search for “ipad” should not display “galaxy” tablets. You do this by using one-way synonyms.
2. Alternative corrections
Alternative corrections are similar to one-way synonyms, except that they are ranked differently: we rank matches on the corrected terms (i.e. the synonyms) lower than an exact match on a query term.
You should use alternative corrections when you want records with an exact match of the query to be ranked higher than a synonym match.
For example, let’s rethink the above pants ⇔ trousers
synonym. Although you want searches for “pants” or “trousers” to return all records with either “pants” or “trousers”, you might want a search for “trousers” to rank results with “dress trousers” higher than results with “casual pants”. This is when you need to use alternative corrections: trousers → pants, typo 1
, which means that the query “trousers” ranks records including “trousers” higher than records including “pants”.
Alternative corrections are thus just like one-way synonyms, except they will generate matches with typos to create a different ranking between the synonyms. You can choose to have an an alternative correction count as one typo or two.
3. Placeholders
Placeholders allow you to place not-yet-defined “tokens” that can take any value from a list of defined words.
For example, “iPhone
Add and manage synonyms
You can manage your synonyms (add, edit, delete) via the Dashboard or the API. You can manage them one-by-one, or in batches, or by importing JSON or CSV files.
What does “Forward to replica indices” mean?
You can apply any synonyms that you create, edit, or delete to an index’s replica indices. This is the default behavior. If you don’t want synonyms to apply to an index’s replicas, make sure the box is unchecked.
Important considerations
Synonyms and plurals
Synonyms do not find plurals. So if you create a “boot” = “shoe” synonym, you’ll have the following behavior:
- “boot” will find “shoe” and “shoes”
- but the plural “boots” will not find “shoe” or “shoes”
You will need to create a new synonym for “boots” that does the same as “boot”. More generally, you’ll need a synonym for every word that you want both the singular and plural to be synonymous.
Synonyms do not produce the same result set
Creating synonyms between terms does not ensure that searches for those terms will provide the exact same results set.
For example, it is expected to have different results for the queries “swimwear” and “swimsuit” even when you have a synonym between those two words.
When you perform the query “swimwear”, we search for “swimwear”, typos of “swimwear”, synonyms of “swimwear”, and plurals and other alternatives of “swimwear”.
When you perform the query “swimsuit”, we search for “swimsuit”, typos of “swimsuit”, synonyms of “swimsuit”, and plurals and other alternatives of “swimsuit”.
In the end, having different results for synonyms is expected because the search for typos, plurals, and other alternatives is not performed on the same words.
If you want two queries to have the exact same results, it’s best to create a Rule that replaces one word in your query with another. For the previous example, if you want the query “swimwear” to produce the exact same results as “swimsuit”, you should create a Rule that replaces the query “swimwear” with “swimsuit”.
Algolia does not provide a synonyms dictionary
Algolia does not provide any built-in synonym dictionary. The reasoning behind this is that synonyms are very use-case dependent. Each customer has their own goals, relying on a unique vocabulary and language to describe their products and services. No single dictionary can adequately cover this variety.
We therefore make it easy for you to create your own personalized list via the dashboard or using one of the API clients.
One way to know which synonyms to add for your use-case is to use Algolia’s analytics feature. By looking at the top queries, especially those with little or no results, you can get a good idea of which synonyms you’ll need to configure.
Dynamic Synonym Suggestions
The Dynamic Synonym Suggestions feature automates the process of generating synonyms based on your users’ behavior.
Algolia AI identifies queries that your users correct, and suggests them as synonyms. For example, if Algolia AI detects that users search for “trousers” then change their query to “pants”, it can suggest the synonym trousers ⇔ pants
. All you have to do is accept, edit, or decline the suggested synonym.
Importing synonyms from a file
If you have many synonyms, perhaps sourced by a merchandising team, or pulled from an external dictionary, you probably don’t want to add them one by one. You can do this by uploading an entire file of synonyms at once. This can be done via the Dashboard or using the API.
Cascading synonyms
Synonyms don’t cascade.
This means that if you set two separate synonyms pairs — for example pants ⇒ trouser
and trouser ⇒ slacks
, pants
won’t match slacks
.
We don’t allow cascading - to avoid unexpected side-effects and to give you full control over your synonym strategy.
If you want this, you’ll need to create the regular synonym group “slacks, pants, trousers”.
Alternative to synonyms
As an alternative to synonyms, you can include an attribute with a list of relevant keywords.
For example, instead of using the above synonyms (slacks, trousers, pants), you can add an other_words
attribute to every record for “pants”, with the values other_words: trousers, slacks
.
By making other_words
a searchable attribute, you’ll get the same result as synonyms.
Ambiguous synonyms
Synonyms are powerful, but sometimes they can lead to surprising or undesirable results. Accordingly, they should be used sparingly.
-
Look out for words with multiple meanings, like “baskets” in the synonym “sneakers = baskets”. When users type “sneaker”, they will see an odd mix of high-top basketball sneakers and hand-knit storage baskets.
-
Look out for common words. Take “photocopier = xerox”, where a search for “photocopier” will be flooded with xerox, and a search for “xerox” will be flooded with non-xerox photocopiers.
What often happens in these situations is that a customer creates many ambiguous synonyms and then tries to correct them with other settings, like adding additional synonyms, Rules, or optional filters, or changing engine settings like typo tolerance.
Multi-word synonym matching
Multi-word synonyms match by sequence expression, meaning in the correct order with nothing in-between.
For example, assuming you have a synonym pair HD ⇔ High Definition
and a query HD
, that query:
-
matches records containing
High Definition
-
doesn’t match records containing
High degree Definition
orDefinition High
.