From 57f138e5970eec559c7b054bc701ae21354d8259 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 21 Jan 2026 16:09:35 +0000 Subject: [PATCH] Fix search filter precedence bug Previous version would do: purchase status + normal filter OR normalized filter New version does: purchase status AND (normal filter OR normalized filter) --- lib/music_library/records.ex | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index fd5e0cd7..22942463 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -97,18 +97,24 @@ defmodule MusicLibrary.Records do escaped_artist = fts_escape(artist) search - |> where(fragment("records_search_index MATCH 'artists : ' || ?", ^escaped_artist)) - |> or_where( - fragment("records_search_index MATCH 'normalized_artists : ' || ?", ^escaped_artist) + |> where( + fragment( + "records_search_index MATCH 'artists : ' || ? OR records_search_index MATCH 'normalized_artists : ' || ?", + ^escaped_artist, + ^escaped_artist + ) ) {:album, album}, search -> escaped_album = fts_escape(album) search - |> where(fragment("records_search_index MATCH 'title : ' || ?", ^escaped_album)) - |> or_where( - fragment("records_search_index MATCH 'normalized_title : ' || ?", ^escaped_album) + |> where( + fragment( + "records_search_index MATCH 'title : ' || ? OR records_search_index MATCH 'normalized_title : ' || ?", + ^escaped_album, + ^escaped_album + ) ) {:genre, genre}, search ->