Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/explore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,9 @@ pub const Explorer = struct {

if (pathHasSegment(r.path, "tests") or pathHasSegment(r.path, "test")) score *= 0.6;
if (pathHasSegment(r.path, "examples") or pathHasSegment(r.path, "example")) score *= 0.6;
if (pathHasSegment(r.path, "bench") or pathHasSegment(r.path, "benchmarks") or
pathHasSegment(r.path, "scripts") or pathHasSegment(r.path, "website") or
pathHasSegment(r.path, "install")) score *= 0.5;
if (pathHasSegment(r.path, "vendor") or pathHasSegment(r.path, "node_modules") or
pathHasSegment(r.path, "third_party")) score *= 0.4;
// Doc-language penalty: markdown / data files (CHANGELOG.md, design
Expand Down
28 changes: 28 additions & 0 deletions src/test_search.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1638,3 +1638,31 @@ test "issue-451: scope=true search surfaces skip-trigram files" {
}
try testing.expect(found_canonical);
}


test "issue-546: searchContent rerank penalizes non-source tooling paths (bench/install/scripts/website)" {
// Mirror of issue-429-b for first-party tooling directories. Five files,
// identical content and hit count — only a path prior can separate them.
// Pre-fix the path-asc tiebreaker puts bench/ first; the implementation
// under src/ must win.
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
var explorer = Explorer.init(arena.allocator(), Explorer.DEFAULT_CONTENT_CACHE_CAPACITY);

try explorer.indexFile("bench/sample.zig", "pub fn x() void { _ = coreTerm; }\n");
try explorer.indexFile("install/sample.zig", "pub fn x() void { _ = coreTerm; }\n");
try explorer.indexFile("scripts/sample.zig", "pub fn x() void { _ = coreTerm; }\n");
try explorer.indexFile("website/sample.zig", "pub fn x() void { _ = coreTerm; }\n");
try explorer.indexFile("src/sample.zig", "pub fn x() void { _ = coreTerm; }\n");

const results = try explorer.searchContent("coreTerm", testing.allocator, 10);
defer {
for (results) |r| {
testing.allocator.free(r.path);
testing.allocator.free(r.line_text);
}
testing.allocator.free(results);
}
try testing.expect(results.len >= 5);
try testing.expectEqualStrings("src/sample.zig", results[0].path);
}
Loading