Skip to content

feat(search): surface the definition line first within the def file (#2 pass 2)#667

Open
justrach wants to merge 1 commit into
feat/def-first-ranking-v2from
feat/def-first-pass2
Open

feat(search): surface the definition line first within the def file (#2 pass 2)#667
justrach wants to merge 1 commit into
feat/def-first-ranking-v2from
feat/def-first-pass2

Conversation

@justrach

@justrach justrach commented Jul 9, 2026

Copy link
Copy Markdown
Owner

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 lineSpans computes 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 bumpSearchGen now leads with explore.zig:2021: fn bumpSearchGen(...) (the def) instead of a comment. Regression test fails on baseline, passes with fix; full zig build test green.

Remaining holdout (separate path, tracked in experiments/ranking/def-first-eval.md): a query that bails to searchContentAutosearchContent (single-word, unranked) still doesn't demote docs.

🤖 Generated with Claude Code

… 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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/explore.zig
// 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 62461 62253 -0.33% -208 OK
codedb_changes 11014 10637 -3.42% -377 OK
codedb_context 296419 290540 -1.98% -5879 OK
codedb_deps 458 382 -16.59% -76 OK
codedb_edit 31432 36227 +15.26% +4795 NOISE
codedb_find 3028 2641 -12.78% -387 OK
codedb_hot 27136 28278 +4.21% +1142 OK
codedb_outline 18235 18380 +0.80% +145 OK
codedb_read 13520 13011 -3.76% -509 OK
codedb_search 61039 61113 +0.12% +74 OK
codedb_snapshot 67803 63776 -5.94% -4027 OK
codedb_status 10245 9567 -6.62% -678 OK
codedb_symbol 52262 58588 +12.10% +6326 NOISE
codedb_tree 21191 23428 +10.56% +2237 NOISE
codedb_word 11726 11814 +0.75% +88 OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant