How to support multi-language compound location se...
# community-help
d
How to support multi-language compound location search (e.g. "Berlin Mitte") with Typesense? I'm building a multilingual location search using Typesense and want to support compound queries like
"Berlin Mitte"
or
"Mitte Berlin"
, where: •
"Mitte"
is the city name (
city_de
) •
"Berlin"
is the parent city (
parent_city_de
) • Both fields exist in several languages (e.g.
city_en
,
parent_city_en
, etc.) Each document in my
Locations
collection contains: •
city_xx
and
parent_city_xx
fields for each language • Coordinates • And some metadata Here's a simplified schema excerpt:
Copy code
{
  "city_de": "Mitte",
  "parent_city_de": "Berlin",
  "city_en": "Mitte",
  "parent_city_en": "Berlin",
  ...
}
Goal: When a user searches for
"Berlin Mitte"
or
"Mitte Berlin"
, the document should match even though
"Berlin"
is in the
parent_city_de
field and
"Mitte"
is in the
city_de
field
. Also, I'd like to prioritize matches based on the user's preferred language, e.g.
de > en > fr
. --- At indexing time, I plan to generate a field like
Combined_search_de
, which concatenates both possible permutations:
Copy code
"Combined_search_de": "Berlin Mitte Mitte Berlin"
And similarly for other languages (
Combined_search_en
,
Combined_search_fr
, etc.). Then, at query time, I would do something like:
Copy code
q=Berlin Mitte
&query_by=Combined_search_de,Combined_search_en
&query_by_weights=5,3
To prioritize German, but still support fallback to English. 1. Is this the best practice for compound field searches across multiple fields in Typesense? 2. Would it be more efficient to use a single
Combined_search
field that contains values from all languages instead of language-specific fields? 3. Are there better alternatives that would allow for searching across multiple fields (
city_de
,
parent_city_de
, etc.) directly — and still get good relevance and ranking? I am unsure what the best practice is for this and thought that some of you had to implement a similar functionality. Thanks in advance 🫶