Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
etchegom committed Feb 25, 2025
1 parent a928821 commit 59fe631
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
44 changes: 10 additions & 34 deletions recoco/apps/addressbook/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions recoco/rest_api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 59fe631

Please sign in to comment.