improved main search results form

This commit is contained in:
Kieran Eglin 2024-05-23 15:00:15 -07:00
parent 2c17482924
commit 7f62ae0a16
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 9 additions and 13 deletions

View file

@ -130,7 +130,8 @@ defmodule Pinchflat.Media.MediaQuery do
def matches_search_term(term) do def matches_search_term(term) do
escaped_term = clean_search_term(term) escaped_term = clean_search_term(term)
case String.trim(escaped_term) do # Matching on `term` instead of `escaped_term` because the latter can mangle empty strings
case String.trim(term) do
"" -> dynamic([mi], true) "" -> dynamic([mi], true)
_ -> dynamic([mi], fragment("media_items_search_index MATCH ?", ^escaped_term)) _ -> dynamic([mi], fragment("media_items_search_index MATCH ?", ^escaped_term))
end end
@ -190,6 +191,9 @@ defmodule Pinchflat.Media.MediaQuery do
# - Wraps any word in quotes (must happen after the double quote replacement) # - Wraps any word in quotes (must happen after the double quote replacement)
# #
# This allows for works with apostrophes and quotes to be searched for correctly # This allows for works with apostrophes and quotes to be searched for correctly
defp clean_search_term(nil), do: ""
defp clean_search_term(""), do: ""
defp clean_search_term(term) do defp clean_search_term(term) do
term term
|> String.trim() |> String.trim()

View file

@ -10,19 +10,13 @@
<%= if match?([_|_], @search_results) do %> <%= if match?([_|_], @search_results) do %>
<.table rows={@search_results} table_class="text-black dark:text-white"> <.table rows={@search_results} table_class="text-black dark:text-white">
<:col :let={result} label="Title"> <:col :let={result} label="Title">
<%= result.title %> <.subtle_link href={~p"/sources/#{result.source_id}/media/#{result.id}"}>
<%= StringUtils.truncate(result.title, 35) %>
</.subtle_link>
</:col> </:col>
<:col :let={result} label="Excerpt"> <:col :let={result} label="Excerpt">
<.highlight_search_terms text={result.matching_search_term} /> <.highlight_search_terms text={result.matching_search_term} />
</:col> </:col>
<:col :let={result} label="" class="flex place-content-evenly">
<.link
href={~p"/sources/#{result.source_id}/media/#{result.id}"}
class="hover:text-secondary duration-200 ease-in-out mx-0.5"
>
<.icon name="hero-eye" />
</.link>
</:col>
</.table> </.table>
<% else %> <% else %>
<p class="font-bold text-lg text-center text-black dark:text-white">No results found</p> <p class="font-bold text-lg text-center text-black dark:text-white">No results found</p>

View file

@ -17,15 +17,13 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
""" """
end end
# TODO: make search results clickable for main search
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div> <div>
<header class="flex justify-between items-center"> <header class="flex justify-between items-center">
<span class="mb-4 flex items-center"> <span class="mb-4 flex items-center">
<.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" /> <.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" />
<span class="ml-2">Showing <%= length(@records) %> of <%= @filtered_record_count %> total</span> <span class="ml-2">Showing <%= length(@records) %> of <%= @filtered_record_count %></span>
</span> </span>
<div class="bg-meta-4 rounded-md"> <div class="bg-meta-4 rounded-md">
<div class="relative"> <div class="relative">