Skip to main content
Synonyms are available in ParadeDB versions 0.27.0 and above.
First, create a table defining synonym rules, which use the pdb.synonym_rule type and follow the Solr syntax.
Next, create an index over the synonym rules.
Finally, run a query searching for all defined synonyms of couch:
This returns Classic leather sofa, even though its description doesn’t contain couch:
Expected Response

Synonym Rules

Every rule must be parseable Solr syntax, otherwise the INSERT will fail.
  • couch, sofa, divan is an equivalence rule. A search for any of these words finds all of them.
  • sneakers => running shoes is a directed rule. A search for sneakers looks for running shoes instead.
  • If a word is present in several rules, a search for it uses the alternatives of all of them. However, rules don’t chain. With sneakers, shoes, trainers and shoes, kicks, a search for shoes finds all four words, but a search for kicks finds only kicks and shoes.
  • A multi-word term matches as a phrase. For example, sofa bed, sleeper couch makes the phrases sofa bed and sleeper couch synonyms. This rule alone does not make their individual words synonyms. Multi-word alternatives require token positions on the field you search.
  • When rules overlap, the longest matching term wins: a rule for running shoes takes priority over a rule for running.
  • Use backslash to escape commas.

Load a Synonym File

In psql, use \copy with a delimiter and a quote character that don’t exist in the file. The ORM tabs insert each line as one rule. Both approaches preserve backslashes and allow blank lines and comments in the rules.

Tokenizers

For correct results, it is important that the synonym index uses the same tokenizer as the field being searched against. This is because at query time, the query is tokenized using the field’s tokenizer, and then those tokens are used to search the synonym index. For example, if the field description is configured to use pdb.simple('stemmer=english'), the synonym rule should be indexed using that same tokenizer.
If your queries require different tokenizers for different fields, create one synonym index for each tokenizer on the same table.

Configuration

Larger synonym sets are more expensive and slow down query performance. The following settings tune the tradeoff between synonym expansion and performance.
default:32
Caps the alternatives for each matching word or phrase, keeping the original terms when the rule includes them. It also caps the total number of phrase combinations searched by a phrase query.
default:1024
Caps the rules read for each synonym key (a word or phrase) in each segment of the synonym index. Without a matching index, it caps the matching rules read from the subquery for each key.