Multilingual search tutorial
Multilingual search is experimental! API may change!
FHIR specifies the translation extension to store translations from the base language of the resource to other languages. In this tutorial, we will cover how to search through resources specifying the language.
First, let's create a resource Location, which has a name in English and French:
Here, translations of the name are specified in the _name, which is FHIR primitive extension.
Search in the specified language
Aidbox has non-FHIR _search-language search parameter to specify the locale to search. Then provide some search-parameter, for example name. To enable _search-language:
To search locations by name in French:
To search in English:
Using Accept-Language header
Accept-Language HTTP header can be used instead of _search-language. To enable such behavior, use this environment variable:
Now we can use the header instead:
Fallback
If desired language is not present in Translation Extension, it will search by search-parameter like without _search-language. This fallback can be turned off by
environment variable (true by default).
Note on field overwriting: Aidbox returns resource in FHIR format without any replacements.
Sorting
_sort
search parameter will use the desired language if Accept-Language
or _search-language
are present.
Collation
By default PostgreSQL uses system locale to specify sort order. When searching by language, SQL will contain GROUP BY <...> COLLATE "<locale>"
. Note that if you want to use the non-default locale you must pass it to Aidboxdb with the EXTRA_LOCALES
environment variable. Also, note that if locale does not contain a territory part (language[_territory]
), Aidbox will use "language_LANGUAGE", e.g. "en_EN" (is not an locale) or "ru_RU" (correct locale).
Collation is supported in Aidboxdb version 14.7+.
Examples
Get all locations, those names start with 'Clinique' in French:
Same with Accept-Language
header:
Get all locations and sort by their names in French, using French locale for sort order (COLLATE):
Array search
If some resource contains an array of strings, e.g. Location.alias
, extensions can also be an array.
_search-language
can search through arrays (search parameter Location.name searches in name
, alias
, _name
and _alias
)
Last updated
Was this helpful?