From 6f792144527e2676084e8dcd5a62f624f6db0bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20Jer=C5=A1e?= Date: Thu, 9 May 2024 11:27:55 +0200 Subject: [PATCH] Use simple_unaccent full text search configuration --- docs/CHANGELOG.rst | 1 + resolwe/flow/filters.py | 2 +- ...create_unaccent_full_text_search_config.py | 29 +++++++++++++++++++ resolwe/flow/tests/test_filtering.py | 3 ++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 resolwe/flow/migrations/0026_create_unaccent_full_text_search_config.py diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 125cd9dd7..36eb10f27 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -13,6 +13,7 @@ Unreleased Changed ------- - **BACKWARD INCOMPATIBLE:** Make move between collections a background job +- Use ``simple_unaccent`` full text search configuration instead of ``simple`` =================== diff --git a/resolwe/flow/filters.py b/resolwe/flow/filters.py index 0104f9bad..e850304ea 100644 --- a/resolwe/flow/filters.py +++ b/resolwe/flow/filters.py @@ -127,7 +127,7 @@ class TextFilterMixin: def filter_text(self, queryset: QuerySet, name: str, value: str): """Full-text search.""" - query = SearchQuery(value, config="simple") + query = SearchQuery(value, config="simple_unaccent") return ( queryset.filter(**{name: query}) # This assumes that field is already a TextSearch vector and thus diff --git a/resolwe/flow/migrations/0026_create_unaccent_full_text_search_config.py b/resolwe/flow/migrations/0026_create_unaccent_full_text_search_config.py new file mode 100644 index 000000000..458b09bfd --- /dev/null +++ b/resolwe/flow/migrations/0026_create_unaccent_full_text_search_config.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.9 on 2024-02-13 07:01 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("flow", "0025_add_unaccent_extension"), + ] + + operations = [ + migrations.RunSQL( + """ + DO + $$BEGIN + CREATE TEXT SEARCH CONFIGURATION simple_unaccent( COPY = simple ); + EXCEPTION + WHEN unique_violation THEN + NULL; -- ignore error + END;$$; + """ + ), + migrations.RunSQL( + "ALTER TEXT SEARCH CONFIGURATION simple_unaccent " + + "ALTER MAPPING FOR hword, hword_part, word " + + "WITH unaccent, simple;" + ), + ] diff --git a/resolwe/flow/tests/test_filtering.py b/resolwe/flow/tests/test_filtering.py index 9bef6d05c..aafba4876 100644 --- a/resolwe/flow/tests/test_filtering.py +++ b/resolwe/flow/tests/test_filtering.py @@ -316,6 +316,9 @@ def test_filter_text(self): self._check_filter({"text": "test"}, self.collections) self._check_filter({"text": "user"}, [self.collections[2]]) + # Test unaccented search. + self._check_filter({"text": "Tešt čollećtion 1"}, [self.collections[1]]) + # By contributor. self._check_filter({"text": "joe"}, self.collections[:2]) self._check_filter({"text": "Miller"}, self.collections[:2])