feat(search): surface the definition line first within the def file (#2 pass 2)#667
feat(search): surface the definition line first within the def file (#2 pass 2)#667justrach wants to merge 1 commit into
Conversation
… pass 2) Follow-up to the def-first ranking (#665). That floated the defining FILE to the top, but the render still showed the file's first hit LINE — often a comment or a call above the definition. Now, within a file that defines the queried symbol, the definition line(s) render before mere mentions. Implementation: after lineSpans computes the per-file spans, stable-move the spans whose line is a definition line (outline symbol named == query) to the front. Reorders the OUTPUT spans only — lineSpans' sorted input is untouched, so offset resolution is unaffected. Same result set, better in-file order. Verified on the pinned eval (scripts/rank-eval.py): def-file rank unchanged (9/10, no regression); qualitatively, `codedb_search bumpSearchGen` now leads with `explore.zig:2021: fn bumpSearchGen(...)` (the def) instead of a comment. Regression test in test_search.zig fails on baseline, passes with the fix; full `zig build test` green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fe53b9135
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Def-line-first: within a file that defines the query symbol, render the | ||
| // definition line(s) before mere mentions — stable-moves matching spans to | ||
| // the front (reorders the OUTPUT spans, not lineSpans' sorted input). | ||
| if (stats.defines) { |
There was a problem hiding this comment.
Select the definition before capping hits
Because this runs only after target_lines has already been truncated to tier0_per_file_cap, it cannot surface the definition when earlier mentions fill the per-file quota (for example, with multiple result files max_results=20 caps each file at 4 lines, so comments/calls above fn query keep the later definition out of spans). In that case stats.defines is true but there is no definition span to move, so codedb_search still renders a non-definition first; the definition line needs to be selected or injected before applying the per-file cap.
Useful? React with 👍 / 👎.
Benchmark Regression ReportThresholds: 10.00% and 50,000 ns absolute delta
|
Stacked on #665. That PR floated the defining file to the top; this one makes the definition line render first within that file (the render was still showing the file's first hit line — often a comment or a call above the def).
How: after
lineSpanscomputes per-file spans, stable-move spans whose line is a definition line (outline symbol named == query) to the front. Reorders the output spans only —lineSpans' sorted input is untouched, so offset resolution is unaffected. Same result set, better in-file order.Verified: pinned eval (
scripts/rank-eval.py) — def-file rank unchanged (9/10, no regression);codedb_search bumpSearchGennow leads withexplore.zig:2021: fn bumpSearchGen(...)(the def) instead of a comment. Regression test fails on baseline, passes with fix; fullzig build testgreen.Remaining holdout (separate path, tracked in
experiments/ranking/def-first-eval.md): a query that bails tosearchContentAuto→searchContent(single-word, unranked) still doesn't demote docs.🤖 Generated with Claude Code