Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ Remaining limitations:
- Only 100 of the 2,000 albums have a track list, taken from one official release
of the release group. The album page says when there are no tracks.
- 21 albums have no release year. They sort last and have no decade facet.
- Search is not accent-insensitive: "beyonce" does not find "Beyoncé", and
names in other scripts (for example Mulatu Astatke as ሙላቱ አስታጥቄ) only match
as written.
- Names in non-Latin scripts (for example Mulatu Astatke as ሙላቱ አስታጥቄ) only
match as written (Latin diacritics are normalized with PostgreSQL `unaccent`).
- Artists are matched by name, so two different artists with the same name
would share a row. None were found in the snapshot.
- Classical albums credit the composer as an artist, and compilations use
Expand Down
43 changes: 43 additions & 0 deletions server/drizzle/0008_unaccent-search.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CREATE EXTENSION IF NOT EXISTS unaccent;
--> statement-breakpoint
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_ts_config
WHERE cfgname = 'simple_unaccent'
AND cfgnamespace = 'public'::regnamespace
) THEN
CREATE TEXT SEARCH CONFIGURATION public.simple_unaccent (COPY = pg_catalog.simple);
END IF;
END
$$;
--> statement-breakpoint
ALTER TEXT SEARCH CONFIGURATION public.simple_unaccent
ALTER MAPPING FOR hword, hword_part, word, numword, numhword, hword_numpart
WITH unaccent, pg_catalog.simple;
--> statement-breakpoint
CREATE OR REPLACE FUNCTION set_album_search_vector()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.search_vector :=
setweight(to_tsvector('public.simple_unaccent', NEW.title), 'A') ||
setweight(
to_tsvector(
'public.simple_unaccent',
COALESCE((
SELECT string_agg(artist.name, ' ')
FROM album_artist
JOIN artist ON artist.id = album_artist.artist_id
WHERE album_artist.album_id = NEW.id
), '')
),
'B'
);
RETURN NEW;
END;
$$;
--> statement-breakpoint
UPDATE album SET title = title;
Loading