feat(library): title-first match core for library search (#144)
CI / ci (push) Canceled after 0s

LibrarySearch — the pure seam behind the search field: title matches
rank ahead of body matches, both halves keep the scan's title order
(#108 Finder order), query trimmed with empty matching nothing, body
text injected so PostStore.readBody (frontmatter-stripped) stays the
call-site reader. 7 pins incl. the real readBody rail; the ranking pin
is flip-verified.
This commit is contained in:
AlexKucera committed 2026-11-03 02:16:09 +01:00
1 parent de1154dacd
commit 488da126d3
2 files changed
+115

No files matched your search

+24
View File
@@ -169,6 +169,30 @@ struct PostsPaneView: View {
}
}
/// #144 (FEAT-004): the library search's pure core — title matches first,
/// then body matches, both halves preserving the scan's title order (#108:
/// Finder order, never re-sorted). nonisolated: the view runs it inside its
/// detached scan task; `bodyOf` is `PostStore.readBody` at the call site,
/// injected so the seam stays testable.
nonisolated enum LibrarySearch {
/// The query is trimmed here; empty (or whitespace-only) matches
/// nothing — the caller renders the sectioned library instead.
static func results(
for query: String,
in candidates: [Post],
bodyOf: @Sendable (Post) -> String?,
) -> [Post] {
let needle = query.trimmingCharacters(in: .whitespacesAndNewlines)
guard !needle.isEmpty else { return [] }
let titleHits = candidates.filter { $0.title.localizedCaseInsensitiveContains(needle) }
let bodyHits = candidates.filter {
!$0.title.localizedCaseInsensitiveContains(needle)
&& (bodyOf($0) ?? "").localizedCaseInsensitiveContains(needle)
}
return titleHits + bodyHits
}
}
/// #21: the library column, shared by the unfocused layout and the focus-mode
/// left reveal overlay — one implementation, both surfaces. Owns the rename +
/// move sheets and the context menu (they travel with the post rows).