MCPcopy Index your code
hub / github.com/coder/coder / scorePath

Function scorePath

agent/filefinder/text.go:252–288  ·  view source on GitHub ↗

scorePath computes a relevance score for a candidate path against a query. The score combines several signals: basename match, basename prefix, exact segment match, word-boundary hits, longest contiguous run, and penalties for depth and length. A return value of 0 means no match (the query is not a

(
	path []byte,
	baseOff int,
	baseLen int,
	depth int,
	query []byte,
	queryTokens [][]byte,
	params scoreParams,
)

Source from the content-addressed store, hash-verified

250// for depth and length. A return value of 0 means no match
251// (the query is not a subsequence of the path).
252func scorePath(
253 path []byte,
254 baseOff int,
255 baseLen int,
256 depth int,
257 query []byte,
258 queryTokens [][]byte,
259 params scoreParams,
260) float32 {
261 if !isSubsequence(path, query) {
262 return 0
263 }
264 var score float32
265 basename := path[baseOff : baseOff+baseLen]
266 if isSubsequence(basename, query) {
267 score += params.BasenameMatch
268 }
269 if hasPrefixFoldASCII(basename, query) {
270 score += params.BasenamePrefix
271 }
272 segments := extractSegments(path)
273 for _, token := range queryTokens {
274 for _, seg := range segments {
275 if equalFoldASCII(seg, token) {
276 score += params.ExactSegment
277 break
278 }
279 }
280 }
281 bh := countBoundaryHits(path, query)
282 score += float32(bh) * params.BoundaryHit
283 lcm := longestContiguousMatch(path, query)
284 score += float32(lcm) * params.ContiguousRun
285 score -= float32(depth) * params.DepthPenalty
286 score -= float32(len(path)) * params.LengthPenalty
287 return score
288}

Callers 1

mergeAndScoreFunction · 0.85

Calls 6

isSubsequenceFunction · 0.85
hasPrefixFoldASCIIFunction · 0.85
extractSegmentsFunction · 0.85
equalFoldASCIIFunction · 0.85
countBoundaryHitsFunction · 0.85
longestContiguousMatchFunction · 0.85

Tested by

no test coverage detected