Set Up Synonyms

A synonym list widens searches: when a query matches an entry, the entry's terms are appended to the query text before scoring. Expansion 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. Matching any of them pulls in the whole group. Use for different words for the same thing: legemiddel / medisin.
  • OneWay — only the source term expands, into terms. Matching a term does not pull in 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 matches characters and finds those by itself. They are not for translation either. A synonym list in two languages makes every search longer and is not a translation; visitors who search in another language are better served by records in that language, or by Search or ask. Inflected forms need no entry when one form begins or ends the other (stol and stoler). The rare exception is an irregular form that shares neither, such as bok and bøker, or mouse and mice.

Widening a query lengthens its text, which lowers Coverage scores proportionally — measure the effect on your own data before deploying a large list.

json
{
  "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 expands through it. The engine works on its own copy of the query, so your Query object is never modified.

csharp
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:

csharp
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