Search v1 (#19)

* Adds description to media items; hooks it up to indexing/media downloading

* Added a search method using postgres fulltext search

* Hooked up search functionality to the search form

* Added persistence to the search form when on search page
This commit is contained in:
Kieran
2024-02-13 17:46:14 -08:00
committed by GitHub
parent 850cf2db73
commit 58771ee37b
25 changed files with 261 additions and 25 deletions
@@ -0,0 +1,9 @@
defmodule Pinchflat.Repo.Migrations.AddDescriptionToMediaItems do
use Ecto.Migration
def change do
alter table(:media_items) do
add :description, :text
end
end
end
@@ -0,0 +1,28 @@
defmodule Pinchflat.Repo.Migrations.AddSearchFieldToMediaItems do
use Ecto.Migration
def up do
execute """
ALTER TABLE media_items
ADD COLUMN searchable tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(description, '')), 'B')
) STORED;
"""
execute """
CREATE INDEX media_items_searchable_idx ON media_items USING gin(searchable);
"""
end
def down do
execute """
DROP INDEX media_items_searchable_idx;
"""
alter table(:media_items) do
remove :searchable
end
end
end