Skip to content

fix(catalog): rank series and movies above episodes in search - #3474

Merged
Quick104 merged 2 commits into
mainfrom
fix/search-rank-series-over-episodes
Nov 4, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/search-rank-series-over-episodes

Conversation

@Quick104

@Quick104 Quick104 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1252 C1; Silo-Server/silo-apple#337 C1; Silo-Server/silo-apple#338 C1; Silo-Server/silo-android#347 C1; Silo-Server/silo-android#348 C1 (all not run yet)

Searching for a show can put one of its episodes above the show and its spinoffs. Searching "dexter" lists Dexter, then the pilot episode (also titled "Dexter"), then Dexter: New Blood and the other series. This shows up wherever search includes episodes: the iOS, tvOS, Android, and Android TV apps, the web app's All tab, and Jellyfin clients that search episodes. This change ranks every series, movie, and other catalog item above every episode. Episodes still appear after them.

The pilot ties the series on exact title. The next keys favor shorter title documents, and an episode's document holds one title while a series' holds its title, original title, and sort title, so the episode outranks every partial series match.

Approach

PostgreSQL search gets a new leading relevance key, media_rank: 1 for catalog items, 0 for episodes. It applies to the general query, the exact episode tier, and cursor continuation. postgresCursorConfig moves to postgres-relevance-v3 because the cursor tuple gained a key. jellycompat search uses the same provider, so it gets the same order without a separate change. The apps show results in server order and need no change.

Media rank orders full-text matches. Fuzzy matches, which run only when full text finds fewer than five results, still follow every full-text match, as before: a typo match for a series should not outrank a real text match for an episode. The architecture doc says so. docs/architecture/postgres-search.md describes the new order.

The Meilisearch provider is unchanged. Its federated search still weights media and episode hits equally, and changing that needs a new indexed field and an index rebuild, so it is left for a separate change.

Validation

  • Go build, gofmt, go vet ./...: clean.
  • make lint-changed and make lint-router-recovery (golangci-lint v2.12.2): 0 issues.
  • Catalog tests against PostgreSQL 18: pass. A new relevance case searches "dexter" across two series and the pilot, on the offset path and one row per cursor page; it fails without this change. The year-suffixed title test used an exact-title episode to stand in for an exact match, so it now uses a movie.
  • Search tests in apiv2, jellycompat, and API handlers: pass.
  • make test-go: every package passes except 11 tests in jellycompat, metadata/nfo, scanner, subtitles/subsync, and playback. They fail the same way on main on the macOS machine used here (case-insensitive file system, a broken local Node install, local FFmpeg and Dolby Vision tooling), and none touch search.
  • Web gate not run; no web files changed.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3474/

Web search (All tab), desktop and mobile, before on b811418 and after on 93dc1c1, plus the API response order for the web request and for the video_with_episodes request the Apple apps send. jellycompat search calls the same provider, so its order follows; the jellycompat search tests pass, and no separate Jellyfin client capture was made.

Risks

  • A search cursor issued before the upgrade is rejected once (invalid_cursor on /api/v2, catalog_cursor_changed on /api/v1), and the client starts the search over.
  • Ranking is now strict by type. Searching an episode's exact title lists any series or movie whose title matches the words before that episode.
  • Servers using Meilisearch keep the old mixed order.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: T3 Code running Claude Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; human verification pending
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Rank series and movies above episodes in catalog search

Search results now sort catalog items (series, movies) ahead of episodes before applying existing relevance keys. Episodes stay in results after catalog items.

  • Adds media_rank as the leading descending cursor term in searchFTSTerms and the first sort key in mixedSearchOrder (search_cursor.go, search_postgres_mixed.go).
  • Candidate rows get a media_rank column: 0 for episodes, 1 for everything else.
  • Exact-episode cursor validation now expects seven relevance scores instead of six, with shifted positions for the trailing cursor values (search_episode_exact.go).
  • Bumps the PostgreSQL relevance cursor config from v2 to v3; cursors issued before the relevance-key change are rejected (search_postgres_cursor_provider.go).
  • Behavioral Change: existing v2 search cursors become invalid; users paginating during deploys must restart their search.

Macroscope summarized 93dc1c1.

- Add media_rank as the first relevance key so an episode titled like its show (Dexter's pilot "Dexter") no longer outranks the series
- Bump the cursor config to postgres-relevance-v3 so older cursors are rejected
- Shift the episode exact-tier cursor key indexes to account for the new key
- Update the search ranking docs and the relevance and year-title DB tests
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 4, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-04T01:05:03.316310Z
We couldn’t complete this review. Comment @codex review to try again.
93dc1c1 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

PostgreSQL search ordering now ranks non-episode catalog items ahead of episodes among full-text matches. Cursor ordering and validation account for the added media-rank key. Database tests and architecture documentation reflect the updated ordering.

Changes: PostgreSQL search ranking

Layer / File(s) Summary
Media-rank ordering
internal/catalog/search_postgres_mixed.go, internal/catalog/search_relevance_db_test.go, internal/catalog/search_year_title_db_test.go, docs/architecture/postgres-search.md
The candidate query assigns episodes rank 0 and other items rank 1, then sorts by media rank before the remaining relevance keys. Database tests and architecture documentation reflect this order.
Cursor alignment
internal/catalog/search_cursor.go, internal/catalog/search_episode_exact.go, internal/catalog/search_postgres_cursor_provider.go, internal/catalog/search_cursor_plan_test.go, internal/catalog/search_relevance_db_test.go
FTS cursor terms and exact-episode cursor validation account for the added ranking key. The cursor configuration changes from postgres-relevance-v2 to postgres-relevance-v3. The continued-search fixture and pagination comparison are updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to d5a95

The ranking and cursor changes preserve the documented full-text ordering contract, with no material merge risk established.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: ranking series and movies above episodes in catalog search.
Description check Passed The description directly explains the search-ranking change, implementation approach, cursor-version impact, validation, risks, and provider scope.
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 7 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish labels Nov 4, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 4, 2026

Copy link
Copy Markdown

Evidence is incomplete for the changed search ordering:

  • Apple search responses: the Evidence section names the video_with_episodes request but does not specify a before-and-after pair; include ordered-result excerpts for the same query on both commits.
  • Jellyfin-compatible search: this path also receives the new ordering, but no Jellyfin-compatible response is named; include before-and-after ordered results for the same query.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cde1aa60-dda2-4d2d-84ed-fb2ae3134f5e
Commits

Reviewing files that changed from the base of the PR and between b811418 and 93dc1c1.

Files selected for processing: 8
  • docs/architecture/postgres-search.md
  • internal/catalog/search_cursor.go
  • internal/catalog/search_cursor_plan_test.go
  • internal/catalog/search_episode_exact.go
  • internal/catalog/search_postgres_cursor_provider.go
  • internal/catalog/search_postgres_mixed.go
  • internal/catalog/search_relevance_db_test.go
  • internal/catalog/search_year_title_db_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@macroscopeapp

macroscopeapp Bot commented Nov 4, 2026

Copy link
Copy Markdown

Android is affected too: All sends no type filter, so the shared search can return episodes and the app preserves the server's changed order. This changes the search data exercised by #347 C1 (Android phone/tablet) and #348 C1 (Android TV). The PR must explain why the behavior changes; its Problem and Approach sections do. Both task results are Not run, so they need human validation after merge, not re-validation of a prior pass.

Suggested fix:
Validation tasks: changes #1252 C1; Silo-Server/silo-apple#337 C1; Silo-Server/silo-apple#338 C1; Silo-Server/silo-android#347 C1; Silo-Server/silo-android#348 C1 (all not run yet)

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@Quick104

Quick104 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Validation impact: added Silo-Server/silo-android#347 C1 and #348 C1 to the Validation tasks: line. Both Android apps send no type filter on All, so they get the new order.

Evidence: the page has before and after web captures plus the API order for the video_with_episodes request. jellycompat search calls the same PostgreSQL provider, so I noted that in the body instead of adding a Jellyfin client capture.

🤖 Claude Code (claude-opus-5-5)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
docs/architecture/postgres-search.md-57-57: 1

57-57: Minor · Maintainability & Code Quality · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Clarify the full-text search subject.

Replace full text finds with the full-text search returns. This wording identifies the operation that produces fewer than five results and removes the ambiguity.

Source: Linters/SAST tools

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 955c5fde-6ac4-42b6-bbc2-01dd69241eea
Commits

Reviewing files that changed from the base of the PR and between 93dc1c1 and d5a9519.

Files selected for processing: 1
  • docs/architecture/postgres-search.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@Quick104
Quick104 merged commit 902744e into main Nov 4, 2026
27 checks passed
@Quick104
Quick104 deleted the fix/search-rank-series-over-episodes branch November 4, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant