Repository navigation
feat(search): add TV episode search support - #397
Conversation
Add mixed PostgreSQL and Meilisearch episode search with access-safe hydration, incremental indexing, and regression coverage for explicit all-media searches.\n\nPart of Silo-Server#396
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughEpisode search support spans legacy routing, PostgreSQL mixed search, Meilisearch federation and filtering, indexing and database event capture, and catalog URL state handling. ChangesEpisode catalog search
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant Catalog
participant SearchProvider
participant Meilisearch
participant ItemRepository
Catalog->>SearchProvider: submit mixed media and episode query
SearchProvider->>Meilisearch: send federated search with access filters
Meilisearch-->>SearchProvider: return ranked content IDs
SearchProvider->>ItemRepository: hydrate IDs with access checks
ItemRepository-->>Catalog: return mixed search results
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 808883cf8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| settings := map[string]any{ | ||
| "displayedAttributes": []string{"content_id", "type"}, | ||
| "filterableAttributes": []string{"type"}, | ||
| "filterableAttributes": []string{"type", "library_ids"}, |
There was a problem hiding this comment.
Force a Meilisearch rebuild for the new document schema
Adding library_ids as a filterable/document field (and indexing episode documents) changes the on-index schema, but catalogSearchMeilisearchSchemaVersion still derives the same value for existing settings. In installs with an already-active Meilisearch index, the provider will accept the old index instead of forcing a rebuild, so unrestricted searches keep missing all pre-existing episodes and library-scoped searches can fall back/error because the served index was created without library_ids as a filterable attribute. Bump the schema identity/version when adding this field so existing indexes are marked stale and rebuilt.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed this is already covered by the PR: SearchMeilisearchSchemaVersion is bumped from 2 to 3, and catalogSearchMeilisearchSchemaVersion includes that base as the million component of the derived identity. Existing v2 indexes therefore mismatch, search falls back to PostgreSQL, and incremental sync remains disabled until rebuild. The focused schema-version tests pass.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/catalog/item_repo_test.go (1)
493-512: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winExercise the episode branch in the lean-CTE regression test.
The test claims to protect broad episode searches but only builds a movie-scoped query. Run the assertion for episode or unscoped search too.
Proposed adjustment
- dataSQL, countSQL, _ := repo.buildSearchSQL("avatar", []string{"movie"}, 20, 0, AccessFilter{}) - - for _, sql := range []string{dataSQL, countSQL} { + for _, itemTypes := range [][]string{{"movie"}, {"episode"}, nil} { + dataSQL, countSQL, _ := repo.buildSearchSQL("avatar", itemTypes, 20, 0, AccessFilter{}) + for _, sql := range []string{dataSQL, countSQL} { // Existing assertions. + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/catalog/item_repo_test.go` around lines 493 - 512, The regression test TestItemRepo_Search_ScoredCTEIsLean currently exercises only the movie branch; update it to build and validate an episode-scoped or unscoped query as well, while preserving the existing wide-column assertions for both dataSQL and countSQL.internal/catalog/search_meilisearch_provider.go (1)
102-104: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
federationUnsupportedis cached forever with no expiry/reset.Once a Meilisearch response is classified as federation-unsupported,
markFederationUnsupported()sets the flag permanently for the process lifetime — there's no TTL or re-probe, unlike the neighboringcapMu/capCache/capCachedAtsemantic-capability cache which is explicitly "rate-limited" and re-checked. A one-off misclassification, transient error, or a live Meilisearch upgrade would permanently downgrade mixed episode+media searches to keyword-only until the process restarts.Consider mirroring the existing capability-cache pattern (add a cached-at timestamp and re-probe after a TTL) so federation support can recover without a restart.
♻️ Suggested direction
federationMu sync.Mutex federationUnsupported bool + federationCheckedAt time.Time } @@ -func (p *MeilisearchSearchProvider) isFederationUnsupported() bool { +func (p *MeilisearchSearchProvider) isFederationUnsupported() bool { p.federationMu.Lock() defer p.federationMu.Unlock() + if p.federationUnsupported && time.Since(p.federationCheckedAt) > federationRecheckInterval { + return false + } return p.federationUnsupported }Also applies to: 514-525
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/catalog/search_meilisearch_provider.go` around lines 102 - 104, Update the federation capability state managed by markFederationUnsupported and its callers to include a cached-at timestamp and TTL-based expiry, mirroring the existing capMu/capCache/capCachedAt pattern. Re-probe Meilisearch after the TTL instead of treating federationUnsupported as permanent, while preserving synchronized access and resetting the unsupported state when a probe succeeds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/catalog/search_postgres_mixed.go`:
- Around line 33-34: Update the episode hydration conditions near
appendEpisodeLibrarySearchAccess to always require the episode’s current library
membership, mirroring the unconditional availability predicate used in the
corresponding flow around line 128. Preserve the existing access-filter behavior
while preventing stale Meilisearch IDs from hydrating after all
episode_libraries rows are removed.
---
Nitpick comments:
In `@internal/catalog/item_repo_test.go`:
- Around line 493-512: The regression test TestItemRepo_Search_ScoredCTEIsLean
currently exercises only the movie branch; update it to build and validate an
episode-scoped or unscoped query as well, while preserving the existing
wide-column assertions for both dataSQL and countSQL.
In `@internal/catalog/search_meilisearch_provider.go`:
- Around line 102-104: Update the federation capability state managed by
markFederationUnsupported and its callers to include a cached-at timestamp and
TTL-based expiry, mirroring the existing capMu/capCache/capCachedAt pattern.
Re-probe Meilisearch after the TTL instead of treating federationUnsupported as
permanent, while preserving synchronized access and resetting the unsupported
state when a probe succeeds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ae6f19fe-0e5c-4ab4-b34e-e6041b5ef12d
📒 Files selected for processing (19)
internal/api/handlers/legacy_read_routes.gointernal/api/handlers/legacy_read_routes_test.gointernal/catalog/item_repo.gointernal/catalog/item_repo_test.gointernal/catalog/search_episode_db_test.gointernal/catalog/search_indexer.gointernal/catalog/search_meilisearch_client.gointernal/catalog/search_meilisearch_client_test.gointernal/catalog/search_meilisearch_provider.gointernal/catalog/search_postgres_mixed.gointernal/catalog/search_provider.gointernal/catalog/search_provider_test.gomigrations/sql/20260713233000_episode_search_indexes.sqlmigrations/sql/20260713233100_episode_search_outbox_triggers.sqlweb/src/components/SearchBar.test.tsxweb/src/components/SearchBar.tsxweb/src/pages/Catalog.tsxweb/src/pages/catalogSearchParams.test.tsweb/src/pages/catalogSearchParams.ts
Retry federated episode searches after the capability cache expires, clear the downgrade after a successful probe, and exercise lean ranking for episode and mixed catalog branches.
|
Addressed the remaining CodeRabbit review follow-ups in
Validation:
|
# Conflicts: # internal/catalog/item_repo.go
A userProvided Meilisearch embedder rejects any document that omits _vectors entirely, failing the whole indexing task once episode documents enter a rebuild batch. Episode docs now carry the documented `_vectors.<embedder>: null` opt-out, and attachDocumentVectors runs the per-document pass even for episode-only batches. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed two commits to make this mergeable and fix a blocker found during dev validation (maintainer edit):
Dev validation (large catalog, semantic enabled):
Known traps to consider before/right after merge:
AI-use disclosure: merge resolution, fix, and dev validation performed with Claude Code (Fable); all changes verified by the repo's Go/frontend test suites plus the live dev deployment above. |
Summary
media_itemsWhy
TV episodes live in
episodes, but both catalog search providers only queried and indexedmedia_items. Searches such as Who Are You? for Silo S03E01 therefore returned no result. The web catalog also converted an explicit all-media selection back to movie-and-series scope during query changes.Rollout
PostgreSQL support and concurrent indexes are deployed first. The Meilisearch schema version is bumped, so an old index safely falls back to PostgreSQL until the normal admin rebuild creates and atomically swaps the mixed catalog index. Explicit Meilisearch
index_typessettings must includeepisodeorall.Validation
go test ./internal/catalogpnpm testsearch regressions pass; full frontend run has 1,259 passing tests and four unrelated existing harness failures (ResizeObserverand missingQueryClientProvider)pnpm run lint(no errors; existing warnings only)pnpm run format:checkpnpm run buildmake migrate-validatemake verify-local-pathsPart of #396
AI-use disclosure
Implemented and reviewed with Codex. The changes were validated with focused PostgreSQL, Meilisearch, API, and frontend regression tests plus repository build, formatting, migration, and path checks.
Summary by CodeRabbit
library_idsfiltering and mixed federated semantic behavior.type=episode.