AtlatestRepositoryfolio
1
;;; Metadata-only searches retain ranking and filters without computing snippets.2
(import (sigil test)3
(sigil fs)4
(sigil path)5
(sigil sqlite)6
(folio store)7
(folio index))9
(define (without-snippets rows)10
(map (lambda (row)11
(filter (lambda (field) (not (eq? (car field) 'snippet))) row))12
rows))14
(test-group "search projections"15
(test "the default retains snippets; opting out preserves ranked metadata and filters"16
(call-with-temp-directory17
(lambda (root)18
(let* ((store (make-folio-store root))19
(dir (store-notes-dir store)))20
(write-file-string (path-join dir "one.md")21
"---\ntags: [alpha]\ncreated: 2025-01-01\nlast-updated: 2026-10-24\n---\n# One\nneedle needle needle λ\n")22
(write-file-string (path-join dir "two.md")23
"---\ntags: [beta]\ncreated: 2024-01-01\n---\n# Two\nneedle λ\n")24
(let* ((idx (make-folio-index store))25
(db (folio-index-db idx)))26
(index-reconcile! idx)27
(let ((ordinary (search-index idx "needle" #f #f)))28
(assert-equal 2 (length ordinary))29
(assert-true30
(every (lambda (row) (string? (cdr (assoc 'snippet row)))) ordinary))31
(assert-equal (without-snippets ordinary)32
(search-index idx "needle" #f #f snippets?: #f)))33
(for-each34
(lambda (options)35
(let* ((query (car options))36
(tag (cadr options))37
(since (caddr options))38
(ordinary (search-index idx query tag since)))39
(assert-equal 1 (length ordinary))40
(assert-equal (without-snippets ordinary)41
(search-index idx query tag since snippets?: #f))))42
'(("needle" "alpha" #f)43
("needle" #f "2026-01-01")44
("λ" "beta" #f)))45
(assert-equal (search-index idx #f #f #f)46
(search-index idx #f #f #f snippets?: #f))47
(assert-equal '() (search-index idx "missingword" #f #f snippets?: #f))48
(sqlite-close db)))))))