ENG-2108 Add ranked search to QueryEngine with a vault-iteration fallback - #1284
ENG-2108 Add ranked search to QueryEngine with a vault-iteration fallback#1284trangdoan982 wants to merge 1 commit into
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| **These are not automated.** `apps/obsidian` has no test runner yet — no vitest, no | ||
| `test` script, no existing test files — and standing one up was deliberately kept out | ||
| of ENG-2108. This file is the spec to port when that lands, and the manual checklist | ||
| until then. |
There was a problem hiding this comment.
🟡 New search ranking code ships without automated tests
The new ranking, filtering and candidate-collection functions are added (rankDiscourseNodesByTitle at apps/obsidian/src/services/QueryEngine.ts:708) with only a hand-written markdown checklist instead of executable tests, so future changes can silently break search ordering.
Impact: Regressions in node search results would not be caught before release.
Repository rule requiring unit tests for new functionality
AGENTS.md (Testing) states "Write unit tests for new functionality" and CONTRIBUTING.md step 4 requires "Write tests that validate your change and/or fix." The PR instead adds apps/obsidian/src/services/__tests__/QueryEngine.search.test-cases.md, a non-executable spec, and explicitly states no test runner exists in apps/obsidian. The functions are pure and injectable via scorer (apps/obsidian/src/services/QueryEngine.ts:712-717), so they are directly unit-testable once a runner is configured.
Prompt for agents
AGENTS.md and CONTRIBUTING.md require unit tests for new functionality, but this PR adds only a markdown checklist. The pure functions createScorer, filterCandidatesByNodeTypeIds and rankDiscourseNodesByTitle in apps/obsidian/src/services/QueryEngine.ts are testable in Node when the obsidian module is aliased to a stub (prepareFuzzySearch is only needed when no scorer is injected). Consider adding a vitest setup to apps/obsidian mirroring apps/roam/vitest.config.mts with an alias for the obsidian package, and porting TC1-TC16 from the markdown spec into real test files.
Was this helpful? React with 👍 or 👎 to provide feedback.
22188a8 to
44c784b
Compare
44c784b to
07bb663
Compare
07bb663 to
f89d51d
Compare
f89d51d to
79938ba
Compare
…back Add a Scorer seam over Obsidian's prepareFuzzySearch, plus the candidate fetch and ranking functions the advanced node search panel needs. Separate the candidate fetch from scoring so the vault scan runs once per search-surface open rather than once per keystroke, and route it through getFilesWithNodeTypeId, which already falls back to vault iteration when Datacore is unavailable. Score and render the same string (file.basename) so SearchResult.matches offsets stay aligned with what renderResults re-slices. Filter by node type before scoring, which leaves results identical but shrinks the number of scorer calls on the per-keystroke path. Rank on SearchResult.score alone; Array.prototype.sort is stable, so equal scores keep candidate order without an explicit tie-break. An empty query returns the full filtered set in title order rather than nothing, so a type filter alone still narrows to a visible list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
79938ba to
9708e95
Compare
Scope check
$scope-checkagainst ENG-2108 and the final diff.Done When: None.Mapping
One file, one concern. Three deviations from the ticket's literal wording, all narrowing rather than expanding:
createScorerwas dropped as a meaningless one-line wrapper overprepareFuzzySearch; theScorertype and thescorer?injection parameter were dropped as unused indirection, soprepareFuzzySearchis called directly; andfilterCandidatesByNodeTypeIdsis exported instead, because the ticket requires callers to memoize the filtered array — which is only possible if the filter is callable on its own. No new dependencies, no migrations, no unrelated refactors.What this does
Adds the search seam for the Obsidian advanced node search panel (F1 of Advanced Node Search (Obsidian)). No UI — the panel is #1285, stacked on this.
QueryEngine.ts:DiscourseNodeCandidate,RankedDiscourseNodegetDiscourseNodeCandidates(){ file, title, nodeTypeId }filterCandidatesByNodeTypeIds(...)rankDiscourseNodesByTitle({...})Three decisions worth reviewing
Datacore first, vault iteration as fallback — via delegation, so it is not visible in this diff. The call chain:
Reusing that method rather than writing a second fallback here is why NF3 holds for free.
Verification
check-typesclean,eslint0 problems on the changed file.The reviewable demo is #1285, stacked on this branch: https://www.loom.com/share/877db7d2de834548a81bca1750bbbecb
🤖 Generated with Claude Code