postgres: rework search

This commit is contained in:
nkanaev
2026-06-13 15:27:08 +01:00
parent 3b42d8c703
commit c554650db9
2 changed files with 9 additions and 23 deletions

View File

@@ -95,33 +95,14 @@ func m01_initial(tx *sql.Tx) error {
date_arrived timestamptz,
last_arrived timestamptz,
status integer,
media_links jsonb
media_links jsonb,
search tsvector
);
create index if not exists idx_item_feed_id on items(feed_id);
create index if not exists idx_item__date_id_status on items(date, id, status);
create unique index if not exists idx_item_guid on items(feed_id, guid);
alter table items add column if not exists search tsvector;
create index if not exists idx_item_search on items using gin(search);
create or replace function items_search_update() returns trigger as $$
begin
new.search := to_tsvector('english',
coalesce(new.title, '') || ' ' ||
coalesce(regexp_replace(new.content, '<[^>]+>', '', 'g'), '')
);
return new;
end;
$$ language plpgsql;
create trigger if not exists trg_items_search_insert
before insert on items
for each row execute function items_search_update();
create trigger if not exists trg_items_search_update
before update of title, content on items
for each row execute function items_search_update();
create table if not exists settings (
key text primary key,
val jsonb