diff --git a/recoco/apps/addressbook/rest.py b/recoco/apps/addressbook/rest.py index fcf20903e..27763e20f 100644 --- a/recoco/apps/addressbook/rest.py +++ b/recoco/apps/addressbook/rest.py @@ -59,45 +59,21 @@ class ContactViewSet(ModelViewSet): filter_backends = [OrgaStartswithFilterBackend] search_fields = [ - ( - "last_name", - {"config": "french_unaccent", "weight": "A"}, - ), - ( - "first_name", - {"config": "french_unaccent", "weight": "A"}, - ), - ( - "email", - {"config": "french_unaccent", "weight": "A"}, - ), - ( - "division", - {"config": "french_unaccent", "weight": "B"}, - ), - ( - "organization__name", - {"config": "french_unaccent", "weight": "B"}, - ), - ( - "organization__group__name", - {"config": "french_unaccent", "weight": "B"}, - ), - ( - "organization__departments__name", - {"config": "french_unaccent", "weight": "C"}, - ), + ("last_name", {"weight": "A"}), + ("first_name", {"weight": "A"}), + ("email", {"weight": "A"}), + ("division", {"weight": "B"}), + ("organization__name", {"weight": "B"}), + ("organization__group__name", {"weight": "B"}), + ("organization__departments__name", {"weight": "C"}), ( "organization__departments__code", - {"weight": "C"}, - ), - ( - "organization__departments__region__name", - {"config": "french_unaccent", "weight": "C"}, + {"config": "simple", "weight": "C"}, ), + ("organization__departments__region__name", {"weight": "C"}), ( "organization__departments__region__code", - {"weight": "C"}, + {"config": "simple", "weight": "C"}, ), ] search_min_rank = 0.05 diff --git a/recoco/rest_api/filters.py b/recoco/rest_api/filters.py index c85ca9e73..528554426 100644 --- a/recoco/rest_api/filters.py +++ b/recoco/rest_api/filters.py @@ -72,9 +72,16 @@ def filter_queryset(self, request, queryset, view): search_vector = None for search_field in search_fields: if isinstance(search_field, tuple): - _vector = SearchVector(search_field[0], **search_field[1]) + _vector = SearchVector( + search_field[0], + **{"config": "french_unaccent", **search_field[1]}, + ) else: - _vector = SearchVector(search_field, config="french_unaccent") + _vector = SearchVector( + search_field, + config="french_unaccent", + ) + if search_vector is None: search_vector = _vector else: