Search by genre

Can also click on genres in detail views.
This commit is contained in:
Claudio Ortolina
2024-11-26 13:35:15 +00:00
parent f0212eeb6f
commit 6339196b17
5 changed files with 42 additions and 18 deletions
+4
View File
@@ -64,6 +64,10 @@ defmodule MusicLibrary.Records do
search
|> where(fragment("records_search_index match 'title : ?*'", literal(^album)))
{:genre, genre}, search ->
search
|> where(fragment("records_search_index match 'genres : ?*'", literal(^genre)))
{:mbid, mbid}, search ->
search
|> where(fragment("records_search_index = '?*'", literal(^mbid)))
+9 -1
View File
@@ -28,6 +28,9 @@ defmodule MusicLibrary.Records.SearchParser do
mbid_filter = ignore(string("mbid:"))
mbid = concat(mbid_filter, query) |> tag(:mbid)
genre_filter = ignore(string("genre:"))
genre = concat(genre_filter, query) |> tag(:genre)
format_filter = ignore(string("format:"))
formats =
@@ -56,7 +59,7 @@ defmodule MusicLibrary.Records.SearchParser do
choice([concat(type_filter, types), ignore(invalid_type)])
|> tag(:type)
search = repeat(choice([artist, album, mbid, space, format, type, query]))
search = repeat(choice([artist, album, mbid, genre, space, format, type, query]))
defparsecp(:search_parser, search)
@@ -75,6 +78,8 @@ defmodule MusicLibrary.Records.SearchParser do
{:ok, %{artist: "the pineapple thief", query: "wilderness"}}
iex> MusicLibrary.Records.SearchParser.parse(~s(artist:"the pineapple thief" format:cd))
{:ok, %{artist: "the pineapple thief", format: :cd}}
iex> MusicLibrary.Records.SearchParser.parse(~s(genre:"psychedelic rock"))
{:ok, %{genre: "psychedelic rock"}}
iex> MusicLibrary.Records.SearchParser.parse("format:vin")
{:ok, %{query: ""}}
iex> MusicLibrary.Records.SearchParser.parse("type:alb")
@@ -111,6 +116,9 @@ defmodule MusicLibrary.Records.SearchParser do
{:mbid, [{:query, [value]}]}, acc ->
Map.put(acc, :mbid, value)
{:genre, [{:query, [value]}]}, acc ->
Map.put(acc, :genre, value)
{:format, [value]}, acc ->
Map.put(acc, :format, value)
@@ -77,7 +77,13 @@
<%= gettext("Genres") %>
</dt>
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
<%= Enum.join(@record.genres, ", ") %>
<.link
:for={genre <- @record.genres}
class="mr-2 text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
patch={~p"/collection?#{%{query: ~s(genre:"#{genre}")}}"}
>
<%= genre %>
</.link>
</dd>
</div>
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
@@ -78,7 +78,13 @@
<%= gettext("Genres") %>
</dt>
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
<%= Enum.join(@record.genres, ", ") %>
<.link
:for={genre <- @record.genres}
class="mr-2 text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
patch={~p"/wishlist?#{%{query: ~s(genre:"#{genre}")}}"}
>
<%= genre %>
</.link>
</dd>
</div>
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">