chore: search cleanup
This commit is contained in:
parent
19d17f70d2
commit
fca18da3f7
36 changed files with 71 additions and 60 deletions
42
queries/functions/search.psql
Normal file
42
queries/functions/search.psql
Normal file
|
@ -0,0 +1,42 @@
|
|||
CREATE OR REPLACE FUNCTION public.search_optimized_index(
|
||||
search_query text,
|
||||
page_size integer,
|
||||
page_offset integer,
|
||||
types text[]
|
||||
) RETURNS TABLE(
|
||||
result_id integer,
|
||||
url text,
|
||||
title text,
|
||||
description text,
|
||||
tags text,
|
||||
genre_name text,
|
||||
genre_url text,
|
||||
type text,
|
||||
total_plays integer,
|
||||
rank real
|
||||
) AS $$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
SELECT
|
||||
s.id::integer AS result_id,
|
||||
s.url,
|
||||
s.title,
|
||||
s.description,
|
||||
array_to_string(s.tags, ', ') AS tags,
|
||||
s.genre_name,
|
||||
s.genre_url,
|
||||
s.type,
|
||||
s.total_plays,
|
||||
ts_rank_cd(
|
||||
to_tsvector('english', s.title || ' ' || s.description || array_to_string(s.tags, ' ')),
|
||||
plainto_tsquery('english', search_query)
|
||||
) AS rank
|
||||
FROM optimized_search_index s
|
||||
WHERE
|
||||
(types IS NULL OR s.type = ANY(types))
|
||||
AND plainto_tsquery('english', search_query) @@
|
||||
to_tsvector('english', s.title || ' ' || s.description || array_to_string(s.tags, ' '))
|
||||
ORDER BY rank DESC
|
||||
LIMIT page_size OFFSET page_offset;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
Reference in a new issue