This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/views/feeds/search.psql

102 lines
No EOL
2.5 KiB
Text

CREATE OR REPLACE VIEW optimized_search_index AS
WITH search_data AS (
SELECT
CONCAT('📝 ', p.title) AS title,
CONCAT('https://coryd.dev', p.url) AS url,
p.tags,
NULL AS genre_name,
NULL AS genre_url
FROM optimized_posts p
UNION ALL
SELECT
CONCAT('🔗 ', l.title, ' via ', l.name) AS title,
l.link AS url,
l.tags,
NULL AS genre_name,
NULL AS genre_url
FROM optimized_links l
UNION ALL
SELECT
CASE
WHEN b.rating IS NOT NULL THEN CONCAT('📖 ', b.title, ' (', b.rating, ')')
ELSE CONCAT('📖 ', b.title)
END AS title,
CONCAT('https://coryd.dev', b.url) AS url,
b.tags,
NULL AS genre_name,
NULL AS genre_url
FROM optimized_books b
WHERE LOWER(b.status) = 'finished'
UNION ALL
SELECT
CASE
WHEN m.rating IS NOT NULL THEN CONCAT('🎥 ', m.title, ' (', m.rating, ')')
ELSE CONCAT('🎥 ', m.title)
END AS title,
CONCAT('https://coryd.dev', m.url) AS url,
m.tags,
NULL AS genre_name,
NULL AS genre_url
FROM optimized_movies m
WHERE m.last_watched IS NOT NULL
UNION ALL
SELECT
CONCAT('🎧 ', ar.name, ' - ', ar.genre_name) AS title,
CONCAT('https://coryd.dev', ar.url) AS url,
ARRAY[ar.genre_name] AS tags,
ar.genre_name,
CONCAT('https://coryd.dev', ar.genre_slug) AS genre_url
FROM optimized_artists ar
UNION ALL
SELECT
CONCAT('🎵 ', g.name) AS title,
CONCAT('https://coryd.dev', g.url) AS url,
NULL AS tags,
g.name AS genre_name,
CONCAT('https://coryd.dev', g.url) AS genre_url
FROM optimized_genres g
UNION ALL
SELECT
CASE
WHEN s.review IS NOT NULL THEN CONCAT('📺 ', s.title, ' (', s.year, ') - ', s.review)
ELSE CONCAT('📺 ', s.title, ' (', s.year, ')')
END AS title,
CONCAT('https://coryd.dev', s.url) AS url,
s.tags,
NULL AS genre_name,
NULL AS genre_url
FROM optimized_shows s
WHERE s.last_watched_at IS NOT NULL
),
search_data_with_id AS (
SELECT
ROW_NUMBER() OVER (ORDER BY url) AS id,
search_data.*
FROM search_data
)
SELECT
json_agg(
json_build_object(
'id', search_data_with_id.id,
'url', search_data_with_id.url,
'title', search_data_with_id.title,
'tags', search_data_with_id.tags,
'genre_name', search_data_with_id.genre_name,
'genre_url', search_data_with_id.genre_url
)
) AS search_index
FROM search_data_with_id;