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.
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""per-user search finds
|
|
|
|
Revision ID: 0030_search_finds
|
|
Revises: 0029_unaccent_search
|
|
Create Date: 2026-06-30
|
|
|
|
Adds the `search_finds` table: a per-user record of which videos a user surfaced via their own
|
|
live YouTube search. This lets "videos I searched for" appear in that user's Mine feed (and the
|
|
Mine Source filter), independent of the global `videos.via_search` flag (which marks a video as
|
|
search-discovered by anyone, for the shared Library's Source filter).
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "0030_search_finds"
|
|
down_revision: Union[str, None] = "0029_unaccent_search"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"search_finds",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("video_id", sa.String(), nullable=False),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=False,
|
|
),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["video_id"], ["videos.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("user_id", "video_id", name="uq_user_search_video"),
|
|
)
|
|
op.create_index("ix_search_finds_user_id", "search_finds", ["user_id"])
|
|
op.create_index("ix_search_finds_video_id", "search_finds", ["video_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_search_finds_video_id", table_name="search_finds")
|
|
op.drop_index("ix_search_finds_user_id", table_name="search_finds")
|
|
op.drop_table("search_finds")
|