Skip to content

refactor(store): run Search through SearchNotes - #246

Merged
bketelsen merged 1 commit into
mainfrom
groom/store-search-delegate
Nov 17, 2026
Merged

bketelsen merged 1 commit into
mainfrom
groom/store-search-delegate

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

Closes the last open item of the grooming list in #213. No change in behavior.

  • internal/store/search.go: (*DB).Search repeated the SQL of (*DB).SearchNotes: the same columns, the same snippet(...), the same bm25(notes_fts, 10.0, 5.0, 1.0, 2.0), files.path order, the same limit clamp and the same error texts. Now Search calls SearchNotes with Query{Match: query} and no filters. Its signature and doc comment stay. So the contract test of task card T-0016 (internal/store/search_test.go) now covers the SQL that note.search runs.
  • Kept on purpose: Search still returns nil hits on every error (SearchNotes returns a non-nil slice), and an empty slice for an empty query. The only difference in how it runs: SearchNotes stops reading rows at the limit in Go, not with SQL LIMIT. The hits are the same.

The state of every other item of #213:

Item State
Put / PutWant, the nested-tag EXISTS clause, valid / showText merged in #235
The side pane block in MainWindow.tsx, the item() menu helper, the sync Author written 5 times merged in #241
(*DB).PruneChanges now called by internal/vault/manager.go (#219, closed)
(*DB).Search this PR
(*DB).GetVault kept: TestDeleteVault uses it to prove that a delete removes the row; its removal would change an existing test
(*Client).DownloadAll kept: a 1-line wrapper of transferAll, pinned by the contract test of task card T-0029 ("Do not edit")
retargetText kept: a 5-line wrapper; it is the test entry to targetSpan, which rewriteLinks uses
NARROW in app/src/app/narrow.ts kept: narrow.test.tsx imports it to mock the media query; its removal would change an existing test
ignored / vaultPathHeld kept apart: not exact opposites, because both are false when the vault lookup fails
24 clix.OutputJSON checks in cmd/notesctl/ kept: a helper still needs an if at each call site

Fixes #213

Risk tier

Risk tier: 1 — a refactor with no change in behavior. No changed file is in .github/risk-paths.json.

Verification

No test changed or was added. The same tests pass before and after.

  • Base 4fa430d, go test -count=1 ./internal/store/: exit 0.
  • Head, go test -count=1 -v ./internal/store/: exit 0; TestSearch, TestSearchSnippets, TestSearchQuery and TestSearchNotes pass.
  • Head, make check (host, umask 022): exit 0, lint 0 issues, 58 packages ok.
  • Head, make ci (with the nsl machine): make ui-check 96 files, 819 tests passed; desktop-build passed. The race run failed only internal/desktop/livepreview TestDeepOrUnclosedLinkTextStaysWithinATimeBound (a 10-second wall-clock bound), with the machine's load average at about 13. That package does not import internal/store (go list -deps). The repeat go test -race -count=1 ./internal/desktop/livepreview/ ./internal/store/ passed.
  • Revert test: exempt (a refactor; the evidence is the same tests green before and after).

Left out on purpose

See the table above.

Search repeated SearchNotes' SQL, snippet and ranking. It now calls
SearchNotes with only a match, so the T-0016 contract test covers the
SQL that note.search runs. No change in behavior.
@github-actions github-actions Bot added the level:L3 Skim label Nov 17, 2026
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review

  • Reviewer: github-copilot/claude-sonnet-5.5. Coder: openai/gpt-6.1-sol.
  • Reviewed: base 4fa430da443170c911736ffcba1a4e661749981a, head 27f5144bf13c2fc49f6d8fab32d77c089b2e1ca9 (1 file, internal/store/search.go). Initial review, 1 of the budget.
  • Verdict: Ready. Blocking: none. No line changes observable behavior: the same hits, order, snippets, limit clamp, empty-query result, error texts, and nil hits on error. The state table of grooming: dead and duplicated code after the native desktop move #213 in the PR body was checked by grep at the head.

Findings (all low, not blocking) and what I did:

  1. The join order of the SQL differs (notes JOIN files JOIN notes_fts); only the query plan can change, and note.search already runs this SQL. Agreed; no change.
  2. The row limit is applied in Go, not with SQL LIMIT; ORDER BY bm25(...) ranks every match in both, and rows closes by defer. Agreed; no change.
  3. The doc comment of SearchNotes says "ranks and snippets as Search does", which the reviewer calls circular now. Not changed: the sentence stays true, and a comment-only change is out of scope for a grooming PR. No follow-up issue.

Revert test: exempt (a refactor; the evidence is the same tests green before and after).

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 17, 2026
@bketelsen
bketelsen merged commit f07797b into main Nov 17, 2026
11 checks passed
@bketelsen
bketelsen deleted the groom/store-search-delegate branch November 17, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grooming: dead and duplicated code after the native desktop move

2 participants