Skip to content

Commit

Permalink
Use simple_unaccent full text search configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed May 16, 2024
1 parent 46732ec commit 6f79214
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``


===================
Expand Down
2 changes: 1 addition & 1 deletion resolwe/flow/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;"
),
]
3 changes: 3 additions & 0 deletions resolwe/flow/tests/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 6f79214

Please sign in to comment.