Merge pull request #8 from cloud8421/cloud8421/support-unicode
Sort records taking into account unicode names
This commit is contained in:
@@ -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"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -2,4 +2,41 @@ defmodule MusicLibrary.Repo do
|
||||
use Ecto.Repo,
|
||||
otp_app: :music_library,
|
||||
adapter: Ecto.Adapters.SQLite3
|
||||
|
||||
def init(_context, config) do
|
||||
{:ok,
|
||||
Keyword.put(config, :load_extensions, [
|
||||
extension_path("unicode")
|
||||
])}
|
||||
end
|
||||
|
||||
def extension_path(name) do
|
||||
[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
|
||||
|
||||
extension =
|
||||
case os do
|
||||
:darwin -> "dylib"
|
||||
:linux -> "so"
|
||||
end
|
||||
|
||||
Path.join([
|
||||
:code.priv_dir(:music_library),
|
||||
"sqlite_extensions",
|
||||
platform,
|
||||
"#{name}.#{extension}"
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# SQLite extensions
|
||||
|
||||
Lifted from <https://github.com/mindreframer/ex_sqlean>, original files under MIT license.
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user