The per-word path fix (#745) brought the backend to parity but not above: the project name still gave the lexically-matching stack a residual dir match + an FTS class-name match, so a backend query that included the project name still ranked the frontend at/above the backend. Derive the project name from go.mod module / package.json name / repo dir, and treat a query word matching it as non-discriminative: drop it from path relevance and from codegraph_explore's PascalCase type-disambiguation bias (reporter's suggestions #1/#2) — unless it's the only query word, so a bare project-name search still scores. Narrow by construction: the down-weighting fires ONLY when a query word matches the derived project name (≥5 chars), so every query that doesn't name the project is byte-identical. On the reporter's repro the backend controllers now top a backend question that includes the project name; queries without it, bare project-name queries, and normal symbol queries are unchanged. Query-time only (no re-index). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
afec1282e1
commit
75ae1e8bd9
@@ -16,7 +16,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import CodeGraph from '../src/index';
|
||||
import { LOW_CONFIDENCE_MARKER } from '../src/context';
|
||||
import { isDistinctiveIdentifier, scorePathRelevance } from '../src/search/query-utils';
|
||||
import { isDistinctiveIdentifier, scorePathRelevance, deriveProjectNameTokens } from '../src/search/query-utils';
|
||||
|
||||
describe('isDistinctiveIdentifier', () => {
|
||||
it('treats plain dictionary words as non-distinctive', () => {
|
||||
@@ -64,6 +64,47 @@ describe('scorePathRelevance per-word scoring (#720)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// The project name is context, not a discriminator: dropping it from path
|
||||
// scoring stops every file under a `<ProjectName>…/` tree from winning on the
|
||||
// name alone, so the rest of the query decides the ranking (#720).
|
||||
describe('project-name down-weighting in path relevance (#720)', () => {
|
||||
it('derives the project name from go.mod / package.json, skipping short names', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-projname-'));
|
||||
try {
|
||||
fs.writeFileSync(path.join(dir, 'go.mod'), 'module example.com/SuperBizAgent\n\ngo 1.21\n');
|
||||
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name: '@acme/superbizagent-web' }));
|
||||
const tokens = deriveProjectNameTokens(dir);
|
||||
expect(tokens.has('superbizagent')).toBe(true);
|
||||
expect(tokens.has('superbizagentweb')).toBe(true);
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('drops a project-name query word from path scoring when other words remain', () => {
|
||||
const proj = new Set(['superbizagent']);
|
||||
// Without the project name dropped, the frontend path wins on it (+5).
|
||||
// With it dropped, only "backend" is left — and it doesn't match this path.
|
||||
const withDrop = scorePathRelevance('SuperBizAgentFrontend/app.js', 'SuperBizAgent backend', proj);
|
||||
const noDrop = scorePathRelevance('SuperBizAgentFrontend/app.js', 'SuperBizAgent backend');
|
||||
expect(withDrop).toBeLessThan(noDrop);
|
||||
expect(withDrop).toBe(0);
|
||||
});
|
||||
|
||||
it('keeps the project-name word when it is the ONLY query word (bare query still scores)', () => {
|
||||
const proj = new Set(['superbizagent']);
|
||||
expect(scorePathRelevance('SuperBizAgentFrontend/app.js', 'SuperBizAgent', proj)).toBe(5);
|
||||
});
|
||||
|
||||
it('does not affect a query that omits the project name', () => {
|
||||
const proj = new Set(['superbizagent']);
|
||||
const path0 = 'internal/controller/chat/chat.go';
|
||||
expect(scorePathRelevance(path0, 'controller chat', proj)).toBe(
|
||||
scorePathRelevance(path0, 'controller chat')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Context ranking — common-word precision & confidence', () => {
|
||||
let testDir: string;
|
||||
let cg: CodeGraph;
|
||||
|
||||
Reference in New Issue
Block a user