fix: updated fuzzy search after merge with sorting
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
carla 2025-10-30 17:16:23 +01:00
parent 5e51f99797
commit 3481b9dadf
3 changed files with 31 additions and 1 deletions

View file

@ -138,6 +138,7 @@ defmodule Mv.Membership.Member do
contains(postal_code, ^q2) or
contains(house_number, ^q2) or
contains(phone_number, ^q2) or
contains(city, ^q2) or ilike(city, ^pat) or
fragment("? % first_name", ^q2) or
fragment("? % last_name", ^q2) or
fragment("? % street", ^q2) or

View file

@ -192,7 +192,10 @@ defmodule MvWeb.MemberLive.Index do
defp apply_search_filter(query, search_query) do
if search_query && String.trim(search_query) != "" do
query
|> filter(expr(fragment("search_vector @@ plainto_tsquery('simple', ?)", ^search_query)))
|> Mv.Membership.Member.fuzzy_search(%{
query: search_query,
fields: [:first_name, :last_name, :street]
})
else
query
end

View file

@ -161,4 +161,30 @@ defmodule Mv.Membership.FuzzySearchTest do
ids = Enum.map(result, & &1.id)
assert s1.id in ids
end
test "substring in city matches mid-string" do
{:ok, b} =
Mv.Membership.create_member(%{
first_name: "City",
last_name: "One",
email: "city1@example.com",
city: "Berlin"
})
{:ok, _m} =
Mv.Membership.create_member(%{
first_name: "City",
last_name: "Two",
email: "city2@example.com",
city: "München"
})
result =
Mv.Membership.Member
|> Mv.Membership.Member.fuzzy_search(%{query: "erl"})
|> Ash.read!()
ids = Enum.map(result, & &1.id)
assert b.id in ids
end
end