Skip to content

Feature: support IMDb ID search#60

Open
souocare wants to merge 1 commit into
jakejarvis:mainfrom
souocare:feat/search-by-imdb-id
Open

Feature: support IMDb ID search#60
souocare wants to merge 1 commit into
jakejarvis:mainfrom
souocare:feat/search-by-imdb-id

Conversation

@souocare

@souocare souocare commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Adds support for searching by IMDb title ID in discover search.
When the query matches an IMDb title ID such as tt14688458, Sofa now uses TMDB’s external ID lookup and maps the returned movie/TV results into the same result shape used by normal discover search.

Regular text search behavior is unchanged.

Testing

  • Searched for IMDb ID-shaped queries such as tt14688458 and tt0407418
  • Verified the IMDb ID branch is used for tt... queries
  • Ran bun run check-types

Summary by cubic

Add IMDb ID search to Discover. If a query looks like an IMDb title ID (e.g., tt14688458), we use TMDB external ID lookup and return mapped movie/TV results. Regular text search is unchanged.

  • New Features
    • Detect IMDb IDs with a regex and route to findByExternalId(..., "imdb_id") from @sofa/tmdb/client.
    • Merge movie_results and tv_results and return them in the same result shape as normal search (page, totals, media_type).

Written for commit 93f5e85. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@souocare is attempting to deploy a commit to the Jake Jarvis' projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel Bot temporarily deployed to Preview – sofa-public-api July 9, 2026 17:21 Inactive
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
sofa-public-api Skipped Skipped Jul 9, 2026 5:21pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/server/src/orpc/procedures/discover.ts">

<violation number="1" location="apps/server/src/orpc/procedures/discover.ts:257">
P3: This leaves stale commented-out search logic in the procedure, which makes the active IMDb branching harder to read and easier to let drift from the real implementation. Since the new ternary below replaces it, removing this block would keep the search flow clearer.</violation>

<violation number="2" location="apps/server/src/orpc/procedures/discover.ts:265">
P2: Type-filtered search can now return the wrong media kind for IMDb ID queries: with `input.type === "movie"`, a TV IMDb ID still comes back because the IMDb branch runs before the `type` branches and merges movie/TV results. Consider passing `type` into `searchByImdbId` or filtering its results to preserve the existing movie/TV search contract.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant UI as Client App
    participant API as ORPC API Route
    participant TMDB as TMDB Client
    participant TMDBExt as TMDB External IDs API
    
    Note over UI,TMDBExt: IMDB ID Search Flow
    
    UI->>API: GET /discover/search?query=tt14688458&type=movie
    API->>API: Validate query, extract search type
    API->>API: Check if query matches IMDB ID pattern (alt branch)
    
    alt IMDB ID query (e.g., tt14688458)
        API->>TMDB: findByExternalId("tt14688458", "imdb_id")
        TMDB->>TMDBExt: GET /find/{external_id}?external_source=imdb_id
        TMDBExt-->>TMDB: { movie_results: [...], tv_results: [...] }
        TMDB-->>API: Response with movie and TV results
        API->>API: Map movie_results -> add media_type: "movie"
        API->>API: Map tv_results -> add media_type: "tv"
        API->>API: Merge results, set page=1, total_pages=1
        API-->>UI: { page: 1, total_results: N, results: [...] }
    else Normal text search
        alt search type = movie
            API->>TMDB: searchMovies("godfather", page)
            TMDB-->>API: Movie search results
        else search type = tv
            API->>TMDB: searchTv("breaking bad", page)
            TMDB-->>API: TV search results
        else multi search
            API->>TMDB: searchMulti("batman", page)
            TMDB-->>API: Multi-type search results
        end
        API-->>UI: Standard paginated search results
    end
    
    Note over API: Both paths return same result shape<br/>(page, total_pages, total_results, results)
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

// ? await searchTv(query, input.page)
// : await searchMulti(query, input.page);

const raw = isImdbIdSearch(query)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Type-filtered search can now return the wrong media kind for IMDb ID queries: with input.type === "movie", a TV IMDb ID still comes back because the IMDb branch runs before the type branches and merges movie/TV results. Consider passing type into searchByImdbId or filtering its results to preserve the existing movie/TV search contract.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/server/src/orpc/procedures/discover.ts, line 265:

<comment>Type-filtered search can now return the wrong media kind for IMDb ID queries: with `input.type === "movie"`, a TV IMDb ID still comes back because the IMDb branch runs before the `type` branches and merges movie/TV results. Consider passing `type` into `searchByImdbId` or filtering its results to preserve the existing movie/TV search contract.</comment>

<file context>
@@ -219,12 +254,21 @@ export const search = os.discover.search.use(authed).handler(async ({ input }) =
+  //       ? await searchTv(query, input.page)
+  //       : await searchMulti(query, input.page);
+
+  const raw = isImdbIdSearch(query)
+    ? await searchByImdbId(query)
+    : type === "movie"
</file context>


const raw =
type === "movie"
// Old Results without seach by imdb id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This leaves stale commented-out search logic in the procedure, which makes the active IMDb branching harder to read and easier to let drift from the real implementation. Since the new ternary below replaces it, removing this block would keep the search flow clearer.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/server/src/orpc/procedures/discover.ts, line 257:

<comment>This leaves stale commented-out search logic in the procedure, which makes the active IMDb branching harder to read and easier to let drift from the real implementation. Since the new ternary below replaces it, removing this block would keep the search flow clearer.</comment>

<file context>
@@ -219,12 +254,21 @@ export const search = os.discover.search.use(authed).handler(async ({ input }) =
 
-  const raw =
-    type === "movie"
+  // Old Results without seach by imdb id
+  // const raw =
+  //   type === "movie"
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant