feat(feed): per-user search finds in Mine scope + full-text relevance search
Two related search improvements: 1) Your own live-search results now belong to your Mine feed. A new per-user search_finds table (migration 0030) records each video you surface via your YouTube search (the route inserts them idempotently). The Mine feed becomes 'your non-hidden subscriptions OR your search finds', and the Source filter now applies in Mine too: organic = subscriptions, search = your search finds, all = both (default stays organic, so the main feed is unchanged). The shared Library keeps using the global via_search flag. 2) Feed search ranks by relevance instead of a whole-phrase substring. A custom unaccent_simple text-search config + GIN index (migration 0031) back a YouTube-like fuzzy match: word-order-independent, multi-word AND, prefix on the word being typed, accent-insensitive. A new 'relevance' sort orders by ts_rank; the channel name still matches as a substring. The rank is scaled to an integer so the keyset cursor pages it exactly (a raw float4 breaks paging). _filtered_query returns the rank expr so only the feed list uses it.
This commit is contained in:
parent
a4abfa402f
commit
6cef826ecc
5 changed files with 208 additions and 22 deletions
49
backend/alembic/versions/0031_title_fts.py
Normal file
49
backend/alembic/versions/0031_title_fts.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
"""full-text relevance search on video titles
|
||||
|
||||
Revision ID: 0031_title_fts
|
||||
Revises: 0030_search_finds
|
||||
Create Date: 2026-06-30
|
||||
|
||||
Adds a PostgreSQL full-text search index over video titles so the feed search box can rank by
|
||||
relevance (a YouTube-like "fuzzy" search: word-order-independent, multi-word AND, prefix on the
|
||||
word being typed) instead of a whole-phrase substring match.
|
||||
|
||||
A custom text-search configuration `unaccent_simple` = the `simple` config (no stemming, no
|
||||
stopwords — right for a multilingual HU/EN/DE catalog) plus the `unaccent` dictionary, so the
|
||||
search stays accent-insensitive ("tiesto" matches "Tiësto"). A GIN expression index on
|
||||
`to_tsvector('public.unaccent_simple', coalesce(title,''))` makes the @@ match fast; the feed
|
||||
query uses the exact same expression so the planner picks the index. `unaccent` is already
|
||||
enabled (migration 0029). The config-based 2-arg to_tsvector is IMMUTABLE, so it's index-safe.
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0031_title_fts"
|
||||
down_revision: Union[str, None] = "0030_search_finds"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
"CREATE TEXT SEARCH CONFIGURATION public.unaccent_simple (COPY = pg_catalog.simple)"
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TEXT SEARCH CONFIGURATION public.unaccent_simple
|
||||
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
|
||||
WITH unaccent, simple
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE INDEX ix_videos_title_fts ON videos
|
||||
USING gin (to_tsvector('public.unaccent_simple', coalesce(title, '')))
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute("DROP INDEX IF EXISTS ix_videos_title_fts")
|
||||
op.execute("DROP TEXT SEARCH CONFIGURATION IF EXISTS public.unaccent_simple")
|
||||
Loading…
Add table
Add a link
Reference in a new issue