2 Commits

  1. 9
      CHANGELOG.md
  2. 14
      lib/mirage/search.ex
  3. 4
      lib/mirage_web/live/search_live/index.html.leex
  4. 31
      lib/mirage_web/live/search_live/search_result_component.ex
  5. 2
      mix.exs

9
CHANGELOG.md

@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.97.0](https://git.inhji.de/inhji/mirage/compare/v0.96.0...v0.97.0) (2021-03-29)
### Features:
* search for tags, closes #51
## [v0.96.0](https://git.inhji.de/inhji/mirage/compare/v0.95.1...v0.96.0) (2021-03-29)

14
lib/mirage/search.ex

@ -22,6 +22,17 @@ defmodule Mirage.Search do
def search_notes(search_term) do
downcased_term = String.downcase(search_term)
topic_query =
from t in Mirage.Topics.Topic,
where: contains(t.text, ^downcased_term),
select: %{
type: "tag",
id: t.id,
title: t.text,
content: "",
url: ""
}
link_query =
from l in Mirage.Links.Link,
where: contains(l.title, ^downcased_term),
@ -33,7 +44,8 @@ defmodule Mirage.Search do
title: l.title,
content: l.content,
url: l.url
}
},
union: ^topic_query
note_query =
from n in Mirage.Notes.Note,

4
lib/mirage_web/live/search_live/index.html.leex

@ -23,6 +23,10 @@
<%= if result.type == "link" do %>
<%= live_component @socket, MirageWeb.SearchLive.SearchResultComponent, result: result, url: Routes.link_show_path(@socket, :show, result.id) %>
<% end %>
<%= if result.type == "tag" do %>
<%= live_component @socket, MirageWeb.SearchLive.SearchResultComponent, result: result, url: Routes.topic_path(@socket, :show, result.id) %>
<% end %>
<% end %>
<% end %>
</div>

31
lib/mirage_web/live/search_live/search_result_component.ex

@ -1,14 +1,33 @@
defmodule MirageWeb.SearchLive.SearchResultComponent do
use MirageWeb, :live_component
def icon(type) do
case type do
"note" -> "bi-journal-text"
"link" -> "bi-bookmark-star"
"tag" -> "bi-tag"
_ -> ""
end
end
def render(assigns) do
~L"""
<article>
<%= live_redirect to: @url do %>
<h2><strong><%= @result.title || @result.url %></strong></h2>
<% end %>
<p><%= raw @result.found_value %></p>
<footer>Found in <strong><%= @result.found_prop %></strong> <%= inspect(@result.occurrence) %></footer>
<article>
<h2>
<strong>
<%= live_redirect to: @url do %>
<%= @result.title || @result.url %>
<% end %>
</strong>
</h2>
<p>
<%= raw @result.found_value %>
</p>
<footer>
<i class="bi <%= icon(@result.type) %>"></i> * Found in <strong><%= @result.found_prop %></strong> * <%= inspect(@result.occurrence) %>
</footer>
</article>
"""
end

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.96.0"
@version "0.97.0"
def project do
[

Loading…
Cancel
Save