From f1d344d8a29900f79c2e8f58a914456cd17712ad Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:42:23 -0700 Subject: [PATCH] Search results sort as the filter dialog says (#959) * Search results sort as the filter dialog says Docs sorted ascending orders backwards and fell back to id order for every descending order (`-size`, `-published_datetime`); it now takes the same `-` prefixed orders as the other searches and rejects unknown ones with a 400. Archives and Docs searches without an order now put the most relevant results first, as Videos does and as the dialog shows. Rank has no direction in the dialog: choosing it sends `rank` (most relevant first) instead of inheriting a descending `-rank` (least relevant first). Co-Authored-By: Claude Opus 5.5 * An old -rank link becomes rank when the filter dialog closes The dialog shows Rank without a direction, but it seeded its draft from the URL unchanged, so Done left a saved `-rank` (least relevant first) in place. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- app/src/components/Files.js | 18 ++++-- app/src/components/SearchFilterModal.test.js | 35 +++++++++++ modules/archive/lib.py | 4 ++ modules/archive/test/test_api.py | 27 +++++++- modules/docs/lib.py | 50 ++++++++------- modules/docs/schema.py | 2 +- modules/docs/test/test_api.py | 65 ++++++++++++++++++++ modules/docs/test/test_lib.py | 2 +- 8 files changed, 170 insertions(+), 33 deletions(-) diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 254cb9a5..b1c74776 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -481,6 +481,9 @@ export function DocSearchFilterButton({size = 'medium'}) { return } +// The search relevance sort; see `SearchFilterModal`. +const RANK_ORDER = 'rank'; + // The app-wide default page size (matches usePages' fallback); used to reset Results Per Page on Clear All. const DEFAULT_SEARCH_LIMIT = 24; @@ -540,7 +543,8 @@ export function SearchFilterModal( // Seed the drafts from the URL each time the modal is opened. React.useEffect(() => { if (open) { - setDraftSort(sort || null); + // Rank has no direction here; an old `-rank` link becomes `rank` when the modal closes. + setDraftSort(sort === `-${RANK_ORDER}` ? RANK_ORDER : (sort || null)); setDraftFilter(filter || null); setDraftTags(activeTags || []); setDraftAnyTag(anyTag || false); @@ -614,17 +618,19 @@ export function SearchFilterModal( setDraftDeep(false); } - // Sort section (operates on the draft). + // Sort section (operates on the draft). Rank has no direction: `rank` is always the most relevant first + // (`-rank` would be the least relevant first), and a sort chosen after it starts descending. const sortKey = draftSort ? draftSort.replace(/^-/, '') : (sorts ? sorts[0]['value'] : null); - const desc = draftSort ? draftSort.startsWith('-') : true; + const isRank = sortKey === RANK_ORDER; + const desc = draftSort && !isRank ? draftSort.startsWith('-') : true; const sortButtons = sorts && sorts.map(o => ); - const directionToggle =