Set Up Synonyms
A synonym list widens searches: a query word, or run of words, that matches an entry is held through the words as typed or any of the entry's terms. So a synonym widens what a search counts: "war film" with film / movie also counts the war movies. It happens at search time: nothing is re-indexed, and changes apply on the very next search.
There are two kinds of entries:
- Multidirectional — all terms are equivalent. Any of them stands for the others. Use for different words for the same thing: legemiddel / medisin.
- OneWay — only the
sourceterm widens, toterms. A search for a term does not find the source or its siblings. Use for acronyms: hms should bring in helse, miljø og sikkerhet, but a search for helse must not become a search for hms.
Multi-word terms are matched as whole phrases, and matching splits on the same delimiters as
indexing, so punctuation like medisin, still triggers the entry.
Synonyms are not for typos or spelling variants: the search finds words within an edit or two by itself. They are not for translation either: visitors who search in another language are better served by records in that language, or by Search or ask. An inflection that shares its beginning with the base is met while it is typed and, in a field matched by pattern, inside words. The case for an entry is an irregular form that shares little with its base, such as bok and bøker, or mouse and mice, and any inflection on a field matched by whole words only.
A record holding a word only through a synonym ranks below the records holding the typed word on
the same typo level, and the result counts them apart (toleranceCounts.throughSynonym). The
reranker reads the query as typed, so a list does not lower the typed words' scores.
{
"Name": "medical-terms",
"Description": "Medical terms and acronyms",
"Entries": [
{ "Direction": "Multidirectional", "Terms": ["legemiddel", "medisin"] },
{ "Direction": "OneWay", "Source": "hms", "Terms": ["helse, miljø og sikkerhet"] }
]
}Assign a list to the engine — every subsequent search reads through it. The engine works on
its own copy of the query, so your Query object is never modified.
engine.SynonymList = new SynonymList
{
Entries =
[
new SynonymEntry { Direction = SynonymDirection.Multidirectional, Terms = ["legemiddel", "medisin"] },
new SynonymEntry { Direction = SynonymDirection.OneWay, Source = "hms", Terms = ["helse, miljø og sikkerhet"] },
]
};File in/out follows the field-configuration pattern:
engine.SaveSynonyms("synonyms.json"); // serialize the current list
engine.LoadSynonyms("synonyms.json"); // load and apply a saved list
engine.SynonymList = null; // search without synonyms again