Trek
This commit is contained in:
@@ -3,9 +3,40 @@ create table item (
|
||||
data jsonb
|
||||
);
|
||||
|
||||
CREATE INDEX idx_item_data
|
||||
ON item USING gin (data jsonb_path_ops);
|
||||
create index idx_item_data
|
||||
on item using gin (data jsonb_path_ops);
|
||||
|
||||
alter table item
|
||||
add column description_tsv tsvector generated always as (
|
||||
to_tsvector('french', data->>'description')
|
||||
) stored;
|
||||
|
||||
create index idx_item_description_tsv
|
||||
on item
|
||||
using gin (description_tsv);
|
||||
|
||||
alter table item
|
||||
add column search_tsv tsvector generated always as (
|
||||
setweight(to_tsvector('french', coalesce(data->>'description', '')), 'A') ||
|
||||
setweight(to_tsvector('french', coalesce(data->>'nom', '')), 'B') ||
|
||||
setweight(to_tsvector('french', coalesce(data->>'categorie', '')), 'C')
|
||||
) STORED;
|
||||
|
||||
|
||||
CREATE INDEX idx_item_search_tsv
|
||||
ON item
|
||||
USING gin (search_tsv);
|
||||
|
||||
/*
|
||||
SELECT
|
||||
id,
|
||||
ts_rank(search_tsv, plainto_tsquery('french', 'miel lavande')) AS rank
|
||||
FROM item
|
||||
WHERE search_tsv @@ plainto_tsquery('french', 'miel lavande')
|
||||
ORDER BY rank DESC;
|
||||
*/
|
||||
|
||||
truncate table item;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
|
||||
Reference in New Issue
Block a user