Synonyms are available in ParadeDB versions
0.27.0 and above.pdb.synonym_rule type and follow the Solr syntax.
couch:
Classic leather sofa, even though its description doesn’t contain couch:
Expected Response
Synonym Rules
Every rule must be parseable Solr syntax, otherwise theINSERT will fail.
couch, sofa, divanis an equivalence rule. A search for any of these words finds all of them.sneakers => running shoesis a directed rule. A search forsneakerslooks forrunning shoesinstead.- 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, trainersandshoes, kicks, a search forshoesfinds all four words, but a search forkicksfinds onlykicksandshoes. - A multi-word term matches as a phrase. For example,
sofa bed, sleeper couchmakes the phrasessofa bedandsleeper couchsynonyms. 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 shoestakes priority over a rule forrunning. - Use backslash to escape commas.
Load a Synonym File
Inpsql, 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 fielddescription is configured to use pdb.simple('stemmer=english'), the synonym rule should be
indexed using that same tokenizer.
Configuration
Larger synonym sets are more expensive and slow down query performance. The following settings tune the tradeoff between synonym expansion and performance.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.