add search to notes

This commit is contained in:
2022-11-19 00:21:14 -05:00
parent b95d3039bb
commit f9be5229e7
8 changed files with 128 additions and 17 deletions

View File

@ -75,7 +75,7 @@ msgid "create invite"
msgstr ""
#: lib/memex_web/live/context_live/index.html.heex:53
#: lib/memex_web/live/note_live/index.html.heex:32
#: lib/memex_web/live/note_live/index.html.heex:43
#: lib/memex_web/live/pipeline_live/index.html.heex:51
#, elixir-autogen, elixir-format
msgid "delete"
@ -88,7 +88,7 @@ msgstr ""
#: lib/memex_web/live/context_live/index.html.heex:43
#: lib/memex_web/live/context_live/show.html.heex:40
#: lib/memex_web/live/note_live/index.html.heex:23
#: lib/memex_web/live/note_live/index.html.heex:34
#: lib/memex_web/live/note_live/show.html.heex:27
#: lib/memex_web/live/pipeline_live/index.html.heex:41
#: lib/memex_web/live/pipeline_live/show.html.heex:35
@ -117,7 +117,7 @@ msgstr ""
msgid "new context"
msgstr ""
#: lib/memex_web/live/note_live/index.html.heex:41
#: lib/memex_web/live/note_live/index.html.heex:52
#, elixir-autogen, elixir-format
msgid "new note"
msgstr ""

View File

@ -15,7 +15,7 @@ msgstr ""
msgid "%{title} created"
msgstr ""
#: lib/memex_web/live/note_live/index.ex:48
#: lib/memex_web/live/note_live/index.ex:57
#, elixir-autogen, elixir-format
msgid "%{title} deleted"
msgstr ""
@ -167,7 +167,7 @@ msgstr ""
msgid "document your processes, attaching contexts to each step"
msgstr ""
#: lib/memex_web/live/note_live/index.ex:24
#: lib/memex_web/live/note_live/index.ex:23
#, elixir-autogen, elixir-format
msgid "edit %{title}"
msgstr ""
@ -267,7 +267,7 @@ msgstr ""
msgid "no invites 😔"
msgstr ""
#: lib/memex_web/live/note_live/index.html.heex:8
#: lib/memex_web/live/note_live/index.html.heex:19
#, elixir-autogen, elixir-format
msgid "no notes found"
msgstr ""

View File

@ -142,7 +142,7 @@ msgid "are you sure you want to make %{invite_name} unlimited?"
msgstr ""
#: lib/memex_web/live/context_live/index.html.heex:51
#: lib/memex_web/live/note_live/index.html.heex:29
#: lib/memex_web/live/note_live/index.html.heex:40
#: lib/memex_web/live/pipeline_live/index.html.heex:49
#, elixir-autogen, elixir-format
msgid "are you sure?"

View File

@ -1,17 +1,41 @@
defmodule Memex.Repo.Migrations.CreateNotes do
use Ecto.Migration
def change do
def up do
create table(:notes, primary_key: false) do
add :id, :binary_id, primary_key: true
add :title, :string
add :content, :text
add :tags, {:array, :string}
add :tags, {:array, :citext}
add :visibility, :string
add :user_id, references(:users, on_delete: :delete_all, type: :binary_id)
timestamps()
end
flush()
execute """
CREATE FUNCTION immutable_array_to_string(text[], text)
RETURNS text LANGUAGE sql IMMUTABLE as $$SELECT array_to_string($1, $2)$$
"""
execute """
ALTER TABLE notes
ADD COLUMN search tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(immutable_array_to_string(tags, ' '), '')), 'B') ||
setweight(to_tsvector('english', coalesce(content, '')), 'C')
) STORED
"""
execute("CREATE INDEX notes_trgm_idx ON notes USING GIN (search)")
end
def down do
drop table(:notes)
execute("DROP FUNCTION immutable_array_to_string(text[], text)")
end
end