Skip to content

Commit

Permalink
feat: adapt search to accept locales and return translated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rdahis committed Sep 20, 2024
1 parent 63e3157 commit 11e68e2
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 60 deletions.
19 changes: 13 additions & 6 deletions backend/apps/api/v1/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@

class Organization(BaseModel):
id: str
name: str
slug: str
name_pt: str
name_en: str
name_es: str
picture: Optional[str]
website: Optional[str]
description: Optional[str]


class Theme(BaseModel):
name: str
slug: str
name_pt: str
name_en: str
name_es: str


class Tag(BaseModel):
name: str
slug: str
name_pt: str
name_en: str
name_es: str


class Entity(BaseModel):
name: str
keyword: str
slug: str
name_pt: str
name_en: str
name_es: str


class RawDataSource(BaseModel):
Expand Down
153 changes: 127 additions & 26 deletions backend/apps/api/v1/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,34 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable):
model_attr="slug",
indexed=False,
)
dataset_name = indexes.CharField(
model_attr="name",
dataset_name_pt = indexes.CharField(
model_attr="name_pt",
null=True,
indexed=False,
)
dataset_description = indexes.CharField(
model_attr="description",
default="",
dataset_name_en = indexes.CharField(
model_attr="name_en",
null=True,
indexed=False,
)
dataset_name_es = indexes.CharField(
model_attr="name_es",
null=True,
indexed=False,
)
dataset_description_pt = indexes.CharField(
model_attr="description_pt",
null=True,
indexed=False,
)
dataset_description_en = indexes.CharField(
model_attr="description_en",
null=True,
indexed=False,
)
dataset_description_es = indexes.CharField(
model_attr="description_es",
null=True,
indexed=False,
)

Expand All @@ -35,12 +56,33 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable):
model_attr="tables__slug",
indexed=False,
)
table_name = indexes.MultiValueField(
model_attr="tables__name",
table_name_pt = indexes.MultiValueField(
model_attr="tables__name_pt",
null=True,
indexed=False,
)
table_name_en = indexes.MultiValueField(
model_attr="tables__name_en",
null=True,
indexed=False,
)
table_name_es = indexes.MultiValueField(
model_attr="tables__name_es",
null=True,
indexed=False,
)
table_description_pt = indexes.MultiValueField(
model_attr="tables__description_pt",
null=True,
indexed=False,
)
table_description_en = indexes.MultiValueField(
model_attr="tables__description_en",
null=True,
indexed=False,
)
table_description = indexes.MultiValueField(
model_attr="tables__description",
table_description_es = indexes.MultiValueField(
model_attr="tables__description_es",
default="",
indexed=False,
)
Expand All @@ -55,8 +97,22 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable):
faceted=True,
indexed=False,
)
organization_name = indexes.MultiValueField(
model_attr="organization__name",
organization_name_pt = indexes.MultiValueField(
model_attr="organization__name_pt",
null=True,
faceted=True,
indexed=False,
)
organization_name_en = indexes.MultiValueField(
model_attr="organization__name_en",
null=True,
faceted=True,
indexed=False,
)
organization_name_es = indexes.MultiValueField(
model_attr="organization__name_es",
null=True,
faceted=True,
indexed=False,
)
organization_picture = indexes.MultiValueField(
Expand All @@ -69,9 +125,19 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable):
default="",
indexed=False,
)
organization_description = indexes.MultiValueField(
model_attr="organization__description",
default="",
organization_description_pt = indexes.MultiValueField(
model_attr="organization__description_pt",
null=True,
indexed=False,
)
organization_description_en = indexes.MultiValueField(
model_attr="organization__description_en",
null=True,
indexed=False,
)
organization_description_es = indexes.MultiValueField(
model_attr="organization__description_es",
null=True,
indexed=False,
)

Expand All @@ -81,37 +147,72 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable):
faceted=True,
indexed=False,
)
tag_name = indexes.MultiValueField(
model_attr="tags__name",
default="",
tag_name_pt = indexes.MultiValueField(
model_attr="tags__name_pt",
null=True,
faceted=True,
indexed=False,
)
tag_name_en = indexes.MultiValueField(
model_attr="tags__name_en",
null=True,
faceted=True,
indexed=False,
)
tag_name_es = indexes.MultiValueField(
model_attr="tags__name_es",
null=True,
faceted=True,
indexed=False,
)

theme_slug = indexes.MultiValueField(
model_attr="themes__slug",
default="",
faceted=True,
indexed=False,
)
theme_name = indexes.MultiValueField(
model_attr="themes__name",
default="",
theme_name_pt = indexes.MultiValueField(
model_attr="themes__name_pt",
null=True,
faceted=True,
indexed=False,
)
theme_name_en = indexes.MultiValueField(
model_attr="themes__name_en",
null=True,
faceted=True,
indexed=False,
)
theme_name_es = indexes.MultiValueField(
model_attr="themes__name_es",
null=True,
faceted=True,
indexed=False,
)

entity_slug = indexes.MultiValueField(
model_attr="tables__observation_levels__entity__slug",
default="",
faceted=True,
indexed=False,
)
entity_name = indexes.MultiValueField(
model_attr="tables__observation_levels__entity__name",
default="",
entity_name_pt = indexes.MultiValueField(
model_attr="tables__observation_levels__entity__name_pt",
null=True,
faceted=True,
indexed=False,
)
entity_name_en = indexes.MultiValueField(
model_attr="tables__observation_levels__entity__name_en",
null=True,
faceted=True,
indexed=False,
)
entity_name_es = indexes.MultiValueField(
model_attr="tables__observation_levels__entity__name_es",
null=True,
faceted=True,
indexed=False,
)

temporal_coverage = indexes.MultiValueField(
default="",
model_attr="coverage",
Expand Down
Loading

0 comments on commit 11e68e2

Please sign in to comment.