expand_query#

dscat.queries.expand_query(cat, query, raw)[source]#

Build an FTS5 MATCH expression from a free-text query.

Each query token becomes an OR-group of the token (as a prefix match) and its synonyms, and the groups are ANDed together. With raw set, the query is returned unchanged.

Parameters:
  • cat (dscat.index.Catalogue) – Open catalogue, read for synonym expansions.

  • query (str) – Free-text query, or a raw MATCH expression when raw is set.

  • raw (bool) – Return query unchanged.

Returns:

An FTS5 MATCH expression.

Return type:

str

Raises:

ValueError – When query has no searchable tokens.