provide SQL scripts for populating search index tables from index.ejsl

This commit is contained in:
Helmut Merz 2023-06-23 11:31:37 +02:00
parent 044fb506ce
commit 852495fdb0
2 changed files with 36 additions and 0 deletions

17
sql/load.sql Normal file
View file

@ -0,0 +1,17 @@
-- load.sql
delete from hugo_input;
\copy hugo_input (data) from 'public/index.ejsl'
insert into hugo_text (site, url, title, content)
select data ->> 'site', data ->> 'url', data ->> 'title', data ->> 'content'
from hugo_input;
-- TODO: fill more columns
-- TODO: on conflict update ...
-- sample query:
-- select to_tsquery('german', 'prolog') as q \gset
-- select url, title,
-- ts_headline(content, :q, 'MaxFragments=3, MaxWords=6, MinWords=3')
-- from hugo_text where :q @@ content_tsv;

19
sql/tables.sql Normal file
View file

@ -0,0 +1,19 @@
-- tables.sql
create table hugo_input (data jsonb);
create table hugo_text (
site text,
url text,
title text,
content text,
title_tsv tsvector generated always as
(to_tsvector('german', coalesce(title, ''))) stored,
content_tsv tsvector generated always as
(to_tsvector('german', coalesce(content, ''))) stored,
primary key (site, url)
);
create index title_tsv_idx on hugo_text using gin (title_tsv);
create index content_tsv_idx on hugo_text using gin (content_tsv);