Skip to content

explore: scope=true search has same skip-trigram invisibility as searchContent #451

@justrach

Description

@justrach

Problem

searchContentWithScope is a separate search pipeline rather than searchContent plus scope annotation. It has the same large-file invisibility pattern as #447: files indexed with skip_trigram=true are only checked after trigram candidates, and only if the result list has not already reached max_results.

That means codedb_search with scope=true can miss canonical definition/call-site files >64KB even if the plain search path is fixed. codedb_callers also calls searchContentWithScope, so call sites in large files are at risk too.

Repro

test "scope search surfaces skip-trigram canonical file" {
    var arena = std.heap.ArenaAllocator.init(testing.allocator);
    defer arena.deinit();
    var explorer = Explorer.init(arena.allocator());

    var i: usize = 0;
    while (i < 12) : (i += 1) {
        var path_buf: [32]u8 = undefined;
        const path = try std.fmt.bufPrint(&path_buf, "small_{d}.zig", .{i});
        try explorer.indexFile(path, "fn s() void { _ = widgetX; }\n");
    }

    const canonical_content =
        "fn canonical() void {\n" ++
        "    _ = widgetX;\n" ++
        "    _ = widgetX;\n" ++
        "    _ = widgetX;\n" ++
        "    _ = widgetX;\n" ++
        "    _ = widgetX;\n" ++
        "}\n";
    try explorer.indexFileSkipTrigram("canonical.zig", canonical_content);

    const results = try explorer.searchContentWithScope("widgetX", testing.allocator, 5);

    var found_canonical = false;
    for (results) |r| {
        if (std.mem.eql(u8, r.path, "canonical.zig")) found_canonical = true;
    }
    try testing.expect(found_canonical);
}

Current observed result for max_results=5:

small_0.zig:1
small_1.zig:1
small_2.zig:1
small_3.zig:1
small_4.zig:1

Expected

The scoped path should share candidate generation/ranking with plain searchContent and only add scope metadata afterward. At minimum, #447-style fixes need to be applied to searchContentWithScope too, otherwise scope=true remains stale after plain search improves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p2Medium priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions