From 06fd591e5f2bc32112fc971bd1389988b27aec42 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 7 Dec 2024 19:38:10 +0100 Subject: [PATCH] Use unicode extension to normalize sorting accented records --- lib/music_library/records.ex | 2 +- lib/music_library/repo.ex | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index 2b19c6d3..8f90bcb7 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -52,7 +52,7 @@ defmodule MusicLibrary.Records do initial_search |> order_by( fragment( - "json_extract(artists, '$[0].sort_name') COLLATE NOCASE ASC, title COLLATE NOCASE ASC" + "unaccent(json_extract(artists, '$[0].sort_name')) COLLATE NOCASE ASC, unaccent(title) COLLATE NOCASE ASC" ) ) diff --git a/lib/music_library/repo.ex b/lib/music_library/repo.ex index ce6174f6..a6967044 100644 --- a/lib/music_library/repo.ex +++ b/lib/music_library/repo.ex @@ -11,26 +11,29 @@ defmodule MusicLibrary.Repo do end def extension_path(name) do - [arch | _rest] = :erlang.system_info(:system_architecture) + [arch | _rest] = + :erlang.system_info(:system_architecture) |> List.to_string() |> String.split("-") {_, os} = :os.type() - platform = case {os, arch} do - {:darwin, "x86_64"} -> "darwin-amd64" - {:darwin, "aarch64"} -> "darwin-aarch64" - {:linux, "x86_64"} -> "linux-amd64" - _other -> raise "Unsupported OS or platform" - end + platform = + case {os, arch} do + {:darwin, "x86_64"} -> "darwin-amd64" + {:darwin, "aarch64"} -> "darwin-aarch64" + {:linux, "x86_64"} -> "linux-amd64" + _other -> raise "Unsupported OS or platform" + end - extension = case os do - :darwin -> "dylib" - :linux -> "so" - end + extension = + case os do + :darwin -> "dylib" + :linux -> "so" + end Path.join([ - :code.priv_dir(:music_library), + :code.priv_dir(:music_library), "sqlite_extensions", platform, "#{name}.#{extension}"