Resolves a locale to the best matching PostgreSQL text search configuration.
PostgreSQL's full-text search stems and filters words per language via a regconfig such as 'french' or 'german'. This module maps a Localize.LanguageTag.t/0 (or any locale identifier accepted by Localize.validate_locale/1) to the built-in configuration for its language, falling back to the language-agnostic 'simple' configuration when PostgreSQL has no stemmer for the language.
The mapping is by the language subtag after locale validation, so regional and script variants resolve to their language's configuration — "pt-BR" to 'portuguese', "zh-Hant-TW" to 'simple' (PostgreSQL has no Chinese stemmer).
The primary public API is config_for/2 and config_for!/2, used by the Localize.Ecto.ts_match/2,3 query macro.
Summary
Functions
Returns the PostgreSQL text search configuration for a locale.
Returns the PostgreSQL text search configuration for a locale or raises.
Functions
@spec config_for(Localize.locale() | String.t(), Keyword.t()) :: {:ok, String.t()} | {:error, Exception.t()}
Returns the PostgreSQL text search configuration for a locale.
Arguments
localeis aLocalize.LanguageTag.t/0, or any locale identifier accepted byLocalize.validate_locale/1. The default isLocalize.get_locale/0.optionsis a keyword list of options.
Options
:availableis a list of configuration names to restrict resolution to — for example the rows ofSELECT cfgname FROM pg_ts_configwhen custom configurations replace the built-ins. A language whose configuration is not in the list falls back to"simple".
Returns
{:ok, config_name}such as{:ok, "german"}, or{:error, exception}iflocaleis not a valid locale.
Examples
iex> Localize.Ecto.TextSearch.config_for("de-AT")
{:ok, "german"}
iex> Localize.Ecto.TextSearch.config_for("pt-BR")
{:ok, "portuguese"}
iex> Localize.Ecto.TextSearch.config_for("ja")
{:ok, "simple"}
iex> Localize.Ecto.TextSearch.config_for("en", available: ["simple"])
{:ok, "simple"}
@spec config_for!(Localize.locale() | String.t(), Keyword.t()) :: String.t()
Returns the PostgreSQL text search configuration for a locale or raises.
Arguments
localeis aLocalize.LanguageTag.t/0, or any locale identifier accepted byLocalize.validate_locale/1. The default isLocalize.get_locale/0.optionsis a keyword list of options. Seeconfig_for/2.
Returns
- A configuration name string such as
"german".
Examples
iex> Localize.Ecto.TextSearch.config_for!("fr-CA")
"french"