fix(search): sort search results by received date descending #520

Merged
guettlibot merged 6 commits from issue-509-fix-search-result-sorting into main 2026-06-07 02:24:25 +00:00
guettlibot commented 2026-06-07 00:57:34 +00:00 (Migrated from codeberg.org)

Summary

  • Search results (, ) were sorted by FTS5 relevance rank () instead of date, so results appeared in a seemingly random order instead of newest-first.
  • After merging FTS results with note-search results the combined list was also never re-sorted.

Changes

  • Changed ORDER BY rankORDER BY e.received_at DESC in both FTS queries so the database already returns the 50 most recent matches.
  • Added merged.sort((a, b) => b.receivedAt.compareTo(a.receivedAt)) after merging FTS + note results so the combined list is always newest-first, consistent with the normal email list view.
  • Added two unit tests verifying sort order for searchEmailsGlobal and searchEmails.

Test plan

  • New unit tests: searchEmailsGlobal returns results sorted by receivedAt descending
  • New unit tests: searchEmails returns results sorted by receivedAt descending
  • Existing search tests continue to pass (filter/scope behaviour unchanged)

Closes #509

## Summary - Search results (, ) were sorted by FTS5 relevance rank () instead of date, so results appeared in a seemingly random order instead of newest-first. - After merging FTS results with note-search results the combined list was also never re-sorted. ## Changes - Changed `ORDER BY rank` → `ORDER BY e.received_at DESC` in both FTS queries so the database already returns the 50 most recent matches. - Added `merged.sort((a, b) => b.receivedAt.compareTo(a.receivedAt))` after merging FTS + note results so the combined list is always newest-first, consistent with the normal email list view. - Added two unit tests verifying sort order for `searchEmailsGlobal` and `searchEmails`. ## Test plan - [x] New unit tests: `searchEmailsGlobal returns results sorted by receivedAt descending` - [x] New unit tests: `searchEmails returns results sorted by receivedAt descending` - [x] Existing search tests continue to pass (filter/scope behaviour unchanged) Closes #509
Sign in to join this conversation.