From be4b10c142d555d21bba7fe9b9681d25cfb766a0 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Sun, 27 Oct 2024 17:48:53 +1100 Subject: [PATCH] feat: locale support in search --- backend/apps/api/v1/search_engines.py | 10 ++++++++-- backend/apps/api/v1/search_indexes.py | 2 +- backend/apps/api/v1/search_views.py | 5 ++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/apps/api/v1/search_engines.py b/backend/apps/api/v1/search_engines.py index aa17a408..3140bdf7 100644 --- a/backend/apps/api/v1/search_engines.py +++ b/backend/apps/api/v1/search_engines.py @@ -23,14 +23,19 @@ def __init__(self, *args, **kwargs): "tokenizer": "edgengram", "filter": ["asciifolding", "lowercase"], }, + "snowball_pt": { + "type": "snowball", + "language": "Portuguese", + "filter": ["asciifolding"], + }, "snowball_en": { "type": "snowball", "language": "English", "filter": ["asciifolding"], }, - "snowball_pt": { + "snowball_es": { "type": "snowball", - "language": "Portuguese", + "language": "Spanish", "filter": ["asciifolding"], }, } @@ -63,6 +68,7 @@ def build_schema(self, fields): "edgengram": {"type": "text", "analyzer": "edgengram"}, "snowball_pt": {"type": "text", "analyzer": "snowball_pt"}, "snowball_en": {"type": "text", "analyzer": "snowball_en"}, + "snowball_es": {"type": "text", "analyzer": "snowball_es"}, } mapping.update({field_class.index_fieldname: field_mapping}) return (content_field_name, mapping) diff --git a/backend/apps/api/v1/search_indexes.py b/backend/apps/api/v1/search_indexes.py index c9c9624c..3488d837 100644 --- a/backend/apps/api/v1/search_indexes.py +++ b/backend/apps/api/v1/search_indexes.py @@ -83,7 +83,7 @@ class DatasetIndex(indexes.SearchIndex, indexes.Indexable): ) table_description_es = indexes.MultiValueField( model_attr="tables__description_es", - default="", + null=True, indexed=False, ) diff --git a/backend/apps/api/v1/search_views.py b/backend/apps/api/v1/search_views.py index aa3d336b..b52a0a8e 100644 --- a/backend/apps/api/v1/search_views.py +++ b/backend/apps/api/v1/search_views.py @@ -33,9 +33,8 @@ def search(self): self.searchqueryset .auto_query(q) .filter_and(**{"text.edgengram": q}) - .filter_or(**{"text.snowball_pt": q}) - .filter_or(**{"text.snowball_en": q}) - ) # fmt: skip + .filter_or(**{f"text.snowball_{self.locale}": q}) + ) else: sqs = self.no_query_found()