chore: fix related books + deduplication

- fixed total plays formatting
- formatted queries
- improved proxy server
This commit is contained in:
Cory Dransfeldt 2024-10-21 12:04:17 -07:00
parent ab50866bb8
commit d2c4c78ff7
No known key found for this signature in database
40 changed files with 985 additions and 1357 deletions

View file

@ -1,21 +1,18 @@
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,
total_count bigint
) AS $$
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 text, -- Changed to text
rank real,
total_count bigint
)
AS $$
BEGIN
RETURN QUERY
SELECT
@ -28,20 +25,19 @@ BEGIN
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,
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, ' '))
ts_rank_cd(to_tsvector('english', s.title || ' ' || s.description || array_to_string(s.tags, ' ')), plainto_tsquery('english', search_query)) 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
s.type = 'post' DESC,
s.content_date DESC NULLS LAST,
rank DESC
LIMIT page_size OFFSET page_offset;
END;
$$ LANGUAGE plpgsql;
$$
LANGUAGE plpgsql;