Guides / Managing results / Optimize search results

Synonyms tell the engine which words and expressions to consider equal - for example, pants ⇔ trousers or mad ⇔ angry. A search for “trousers” also returns “pants”, and a search for “pants” also returns “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”.

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:

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” shouldn’t display “galaxy” tablets. You do this by using one-way synonyms.

Alternative corrections

Alternative corrections are similar to one-way synonyms, except that they’re ranked differently: Algolia ranks matches on the corrected terms—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 rank higher than a synonym match. For example, consider the 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 generate matches with typos to create a different ranking between the synonyms. You can choose to have an alternative correction count as one typo or two.

Placeholders

Placeholders allow you to place not-yet-defined “tokens” that can take any value from a list of defined words.

For example, “iPhone <version>” can mean “iPhone 7” or “iPhone 5S”. Essentially “<version>” can be replaced by any of the following: “3G”, “3GS”, “4”, “4S”, “5”, “5C”, “5S”, “6”, “6S”, “7”, “8”, “X”.

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 don’t find plurals. If you create a “boot” = “shoe” synonym, you get the following behavior:

  • “boot” returns “shoe” and “shoes”
  • but the plural “boots” doesn’t return “shoe” or “shoes”

You need to create a new synonym for “boots” that does the same as “boot”. More generally, you need to create a synonym for every word that you want both the singular and plural to be synonymous.

Synonyms don’t produce the same result set

Creating synonyms between terms doesn’t ensure that searches for those terms provide the exact same results set.

For example, it’s 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”, Algolia searches for “swimwear”, typos of “swimwear”, synonyms of “swimwear”, and plurals and other alternatives of “swimwear”.

When you perform the query “swimsuit”, Algolia 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 isn’t 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 doesn’t provide a synonyms dictionary

Algolia doesn’t 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.

Therefore, you can 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, 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 doesn’t match slacks. This avoids unexpected side-effects and to give you full control over your synonym strategy. If you want this behavior, you 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 preceding 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 get the same result as synonyms.

Ambiguous synonyms

Synonyms are powerful, but sometimes they can lead to surprising or undesirable results. Accordingly, you should use them sparingly.

  • Look out for words with multiple meanings, like “baskets” in the synonym “sneakers = baskets”. When users type “sneaker”, they 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 user creates many ambiguous synonyms and then tries to correct them with other settings, like adding extra 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 or Definition High.

Did you find this page helpful?