Changed sqlite FTS to use a trigram tokenizer
This commit is contained in:
parent
8b0b41186a
commit
43005b9a2f
2 changed files with 60 additions and 0 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 445 KiB After Width: | Height: | Size: 449 KiB |
|
|
@ -0,0 +1,60 @@
|
|||
defmodule Pinchflat.Repo.Migrations.ChangeMediaItemsSearchIndexTokenizer do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
# These all need to run as part of separate `execute` blocks. Do NOT ask me why.
|
||||
execute "DROP TRIGGER media_items_search_index_insert;"
|
||||
execute "DROP TRIGGER media_items_search_index_update;"
|
||||
execute "DROP TRIGGER media_items_search_index_delete;"
|
||||
execute "DROP TABLE media_items_search_index;"
|
||||
|
||||
execute """
|
||||
CREATE VIRTUAL TABLE media_items_search_index USING fts5(
|
||||
title,
|
||||
description,
|
||||
tokenize=trigram
|
||||
);
|
||||
"""
|
||||
|
||||
execute """
|
||||
CREATE TRIGGER media_items_search_index_insert AFTER INSERT ON media_items BEGIN
|
||||
INSERT INTO media_items_search_index(
|
||||
rowid,
|
||||
title,
|
||||
description
|
||||
)
|
||||
VALUES(
|
||||
new.id,
|
||||
new.title,
|
||||
new.description
|
||||
);
|
||||
END;
|
||||
"""
|
||||
|
||||
execute """
|
||||
CREATE TRIGGER media_items_search_index_update AFTER UPDATE ON media_items BEGIN
|
||||
UPDATE media_items_search_index SET
|
||||
title = new.title,
|
||||
description = new.description
|
||||
WHERE
|
||||
rowid = old.id;
|
||||
END;
|
||||
"""
|
||||
|
||||
execute """
|
||||
CREATE TRIGGER media_items_search_index_delete AFTER DELETE ON media_items BEGIN
|
||||
DELETE FROM media_items_search_index WHERE rowid = old.id;
|
||||
END;
|
||||
"""
|
||||
|
||||
# Fully re-index the media_items table
|
||||
execute """
|
||||
INSERT INTO media_items_search_index(rowid, title, description)
|
||||
SELECT id, title, description FROM media_items;
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
execute "DROP TABLE media_items_search_index;"
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue