feat: refined search
This commit is contained in:
parent
a141dd5ce0
commit
4893256340
5 changed files with 20 additions and 10 deletions
|
@ -13,7 +13,8 @@ CREATE OR REPLACE FUNCTION public.search_optimized_index(
|
|||
genre_url text,
|
||||
type text,
|
||||
total_plays integer,
|
||||
rank real
|
||||
rank real,
|
||||
total_count bigint
|
||||
) AS $$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
|
@ -30,13 +31,17 @@ BEGIN
|
|||
ts_rank_cd(
|
||||
to_tsvector('english', s.title || ' ' || s.description || array_to_string(s.tags, ' ')),
|
||||
plainto_tsquery('english', search_query)
|
||||
) AS rank
|
||||
) AS rank,
|
||||
COUNT(*) OVER () AS total_count
|
||||
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
|
||||
ORDER BY
|
||||
s.type = 'post' DESC,
|
||||
s.content_date DESC NULLS LAST,
|
||||
rank DESC
|
||||
LIMIT page_size OFFSET page_offset;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
Reference in a new issue