# Synonyms

The synonyms feature allows you to define search terms that should be considered equivalent. For eg: 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:

  1. One-way synonyms: 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.

  2. Multi-way synonyms: Defining the words blazer, coat and jacket as multi-way synonyms 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).

Precedence

When using Synonyms and Overrides together, Overrides are handled first since the rules can contain instructions to replace the query. Synonyms will then work on the modified query.

# Create or update a synonym

# Multi-way synonym

# Sample Response

# One-way synonym

# Sample Response

# Definition

PUT ${TYPESENSE_HOST}/collections/:collection/synonyms/:id

# Arguments

Parameter Required Description
synonyms yes Array of words that should be considered as synonyms.
root no For 1-way synonyms, indicates the root word that words in the synonyms parameter map to.
locale no Locale for the synonym, leave blank to use the standard tokenizer.
symbols_to_index no By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is.

# Retrieve a synonym

We can retrieve a single synonym.

# Sample Response

# Definition

GET ${TYPESENSE_HOST}/collections/:collection/synonyms/:id

# List all synonyms

List all synonyms associated with a given collection.

# Sample Response

# Definition

GET ${TYPESENSE_HOST}/collections/:collection/synonyms

# Delete a synonym

Delete a synonym associated with a collection.

# Sample Response

# Definition

DELETE ${TYPESENSE_HOST}/collections/:collection/synonyms/:id

Last Updated: 9/11/2023, 10:12:44 AM