From 1e211ce32aa4ae01be2d859a122415fe2ad90578 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 13 Sep 2025 08:28:57 +0300 Subject: [PATCH] Simplify by removing search parser escape --- lib/music_library/records.ex | 11 +++----- lib/music_library/records/search_parser.ex | 29 +++------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index 3f845be0..2e49d3f5 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -59,18 +59,13 @@ defmodule MusicLibrary.Records do end defp fts_escape(term) do - # The SearchParser may have already doubled single quotes - # For FTS5, we need to wrap special terms in double quotes instead - # First, undo the SearchParser's quote doubling - clean_term = String.replace(term, "''", "'") - # For FTS5, if the term contains special characters, we need to wrap it in double quotes - if String.contains?(clean_term, ["'", " ", "\"", "(", ")", "^", "-", ":"]) do + if String.contains?(term, ["'", " ", "\"", "(", ")", "^", "-", ":"]) do # Escape internal double quotes and wrap in double quotes - escaped = String.replace(clean_term, "\"", "\"\"") + escaped = String.replace(term, "\"", "\"\"") "\"#{escaped}\"*" else - "#{clean_term}*" + "#{term}*" end end diff --git a/lib/music_library/records/search_parser.ex b/lib/music_library/records/search_parser.ex index 793626bc..b8cde5d0 100644 --- a/lib/music_library/records/search_parser.ex +++ b/lib/music_library/records/search_parser.ex @@ -86,8 +86,6 @@ defmodule MusicLibrary.Records.SearchParser do {:ok, %{query: ""}} iex> MusicLibrary.Records.SearchParser.parse("type:album") {:ok, %{type: :album}} - iex> MusicLibrary.Records.SearchParser.parse("Spock's Beard") - {:ok, %{query: "Spock''s Beard"}} """ def parse(""), do: {:ok, %{query: ""}} @@ -110,26 +108,16 @@ defmodule MusicLibrary.Records.SearchParser do defp normalize(result) do Enum.reduce(result, %{}, fn {:artist, [{:query, [value]}]}, acc -> - Map.update( - acc, - :artist, - escape_special_characters(value), - &(&1 <> " " <> escape_special_characters(value)) - ) + Map.update(acc, :artist, value, &(&1 <> " " <> value)) {:album, [{:query, [value]}]}, acc -> - Map.update( - acc, - :album, - escape_special_characters(value), - &(&1 <> " " <> escape_special_characters(value)) - ) + Map.update(acc, :album, value, &(&1 <> " " <> value)) {:mbid, [{:query, [value]}]}, acc -> Map.put(acc, :mbid, value) {:genre, [{:query, [value]}]}, acc -> - Map.put(acc, :genre, escape_special_characters(value)) + Map.put(acc, :genre, value) {:format, [value]}, acc -> Map.put(acc, :format, value) @@ -138,12 +126,7 @@ defmodule MusicLibrary.Records.SearchParser do Map.put(acc, :type, value) {:query, [value]}, acc -> - Map.update( - acc, - :query, - escape_special_characters(value), - &(&1 <> " " <> escape_special_characters(value)) - ) + Map.update(acc, :query, value, &(&1 <> " " <> value)) _, %{} -> %{query: ""} @@ -152,8 +135,4 @@ defmodule MusicLibrary.Records.SearchParser do acc end) end - - defp escape_special_characters(value) do - String.replace(value, "'", "''") - end end