From 7f62ae0a16ba1bfc915875dc86b20d87191763e9 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 23 May 2024 15:00:15 -0700 Subject: [PATCH] improved main search results form --- lib/pinchflat/media/media_query.ex | 6 +++++- .../controllers/searches/search_html/show.html.heex | 12 +++--------- .../sources/source_html/media_item_table_live.ex | 4 +--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/pinchflat/media/media_query.ex b/lib/pinchflat/media/media_query.ex index 95e3c67..2eeb5f9 100644 --- a/lib/pinchflat/media/media_query.ex +++ b/lib/pinchflat/media/media_query.ex @@ -130,7 +130,8 @@ defmodule Pinchflat.Media.MediaQuery do def matches_search_term(term) do 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], fragment("media_items_search_index MATCH ?", ^escaped_term)) end @@ -190,6 +191,9 @@ defmodule Pinchflat.Media.MediaQuery do # - 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 + defp clean_search_term(nil), do: "" + defp clean_search_term(""), do: "" + defp clean_search_term(term) do term |> String.trim() diff --git a/lib/pinchflat_web/controllers/searches/search_html/show.html.heex b/lib/pinchflat_web/controllers/searches/search_html/show.html.heex index 22ea5dd..47a09fb 100644 --- a/lib/pinchflat_web/controllers/searches/search_html/show.html.heex +++ b/lib/pinchflat_web/controllers/searches/search_html/show.html.heex @@ -10,19 +10,13 @@ <%= if match?([_|_], @search_results) do %> <.table rows={@search_results} table_class="text-black dark:text-white"> <:col :let={result} label="Title"> - <%= result.title %> + <.subtle_link href={~p"/sources/#{result.source_id}/media/#{result.id}"}> + <%= StringUtils.truncate(result.title, 35) %> + <:col :let={result} label="Excerpt"> <.highlight_search_terms text={result.matching_search_term} /> - <: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" /> - - <% else %>

No results found

diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index d6e3d2a..4f504de 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -17,15 +17,13 @@ defmodule Pinchflat.Sources.MediaItemTableLive do """ end - # TODO: make search results clickable for main search - def render(assigns) do ~H"""
<.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" /> - Showing <%= length(@records) %> of <%= @filtered_record_count %> total + Showing <%= length(@records) %> of <%= @filtered_record_count %>