Skip to content

fix(blog): return results newest first#7898

Open
mhartington wants to merge 1 commit into
mainfrom
blog-search-results
Open

fix(blog): return results newest first#7898
mhartington wants to merge 1 commit into
mainfrom
blog-search-results

Conversation

@mhartington
Copy link
Copy Markdown
Member

@mhartington mhartington commented May 11, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Search results are now deduplicated, collapsing multiple matches for the same blog post into a single entry
  • New Features

    • Publication dates are now displayed in search results
    • Search results are automatically sorted by date, showing newest articles first

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

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

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment May 11, 2026 7:51pm
docs Ready Ready Preview, Comment May 11, 2026 7:51pm
eclipse Ready Ready Preview, Comment May 11, 2026 7:51pm
site Ready Ready Preview, Comment May 11, 2026 7:51pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

Walkthrough

The PR extends the blog search API to include date-based sorting and deduplication. The BlogSearchResult type gains a date field, and the search handler normalizes Mixedbread chunk hits into a deduplicated, date-sorted result list while extracting and narrowing generically-stored metadata into specific frontmatter fields.

Changes

Blog Search Date Sorting and Deduplication

Layer / File(s) Summary
Data Shape
apps/blog/src/lib/search-types.ts
BlogSearchResult adds a new date: string field to hold the indexed post publication date.
Search Handler
apps/blog/src/app/api/search/route.ts
The transform function normalizes Mixedbread hits by extracting generated_metadata into indexed fields, sorting results by date (descending), and deduplicating multiple chunk matches per post by URL. A comment documents that generated_metadata is stored generically but maps to specific blog frontmatter fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main objective of the changeset: adding date-sorting functionality to return blog search results in newest-first order.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@apps/blog/src/app/api/search/route.ts`:
- Around line 41-43: The sort comparator is calling localeCompare on
metadata.date which may be undefined; update the comparator and any direct date
comparisons (and the other comparisons at the same spots) to guard and normalize
the value first — e.g., compute safeDateA = String(a.generated_metadata?.date ??
"") and safeDateB = String(b.generated_metadata?.date ?? "") (or use
metadata?.date ?? "" when you already have metadata variable) and call
safeDateA.localeCompare(safeDateB); similarly ensure any other uses of
metadata.date (and other loosely-typed generated_metadata fields referenced
around the same code) are null-coalesced to a safe default before calling string
methods.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ff9d2e1-daaf-40ec-b01a-899fd2539056

📥 Commits

Reviewing files that changed from the base of the PR and between 00c5061 and 0c480fd.

📒 Files selected for processing (2)
  • apps/blog/src/app/api/search/route.ts
  • apps/blog/src/lib/search-types.ts

Comment on lines +41 to +43
const metadata = item.generated_metadata as unknown as GeneratedMetadata;
const slug = (metadata?.slug ?? "").replace(/^\/+/, "");
const title = metadata?.metaTitle ?? metadata?.title ?? "Untitled";
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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Guard date before sorting to avoid runtime crashes.

Because generated_metadata is loosely typed, metadata.date can be missing; then Line 63 can throw when calling localeCompare on undefined.

Proposed fix
-        const metadata = item.generated_metadata as unknown as GeneratedMetadata;
+        const metadata = item.generated_metadata as Partial<GeneratedMetadata> | undefined;
         const slug = (metadata?.slug ?? "").replace(/^\/+/, "");
         const title = metadata?.metaTitle ?? metadata?.title ?? "Untitled";
+        const date = typeof metadata?.date === "string" ? metadata.date : "";
         const formattedUrl = slug ? `/${slug}` : "#";
         const base = `${item.file_id}-${item.chunk_index}`;
@@
-            date: metadata.date,
+            date,
           },
         ];
@@
-      .sort((a, b) => b.date.localeCompare(a.date))
+      .sort((a, b) => b.date.localeCompare(a.date))

Also applies to: 56-57, 63-63

🤖 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 `@apps/blog/src/app/api/search/route.ts` around lines 41 - 43, The sort
comparator is calling localeCompare on metadata.date which may be undefined;
update the comparator and any direct date comparisons (and the other comparisons
at the same spots) to guard and normalize the value first — e.g., compute
safeDateA = String(a.generated_metadata?.date ?? "") and safeDateB =
String(b.generated_metadata?.date ?? "") (or use metadata?.date ?? "" when you
already have metadata variable) and call safeDateA.localeCompare(safeDateB);
similarly ensure any other uses of metadata.date (and other loosely-typed
generated_metadata fields referenced around the same code) are null-coalesced to
a safe default before calling string methods.

@argos-ci
Copy link
Copy Markdown

argos-ci Bot commented May 11, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - May 11, 2026, 7:59 PM

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.

2 participants