scorePathRelevance as it was, re-splitting the query for every path.
(filePath: string, query: string, projectNameTokens?: Set<string>, isDeprioritized?: boolean)
| 340 | describe('path relevance scores are unchanged by the per-query cache (#2620)', () => { |
| 341 | /** scorePathRelevance as it was, re-splitting the query for every path. */ |
| 342 | function reference(filePath: string, query: string, projectNameTokens?: Set<string>, isDeprioritized?: boolean): number { |
| 343 | const pathLower = filePath.toLowerCase(); |
| 344 | const fileName = path.basename(filePath).toLowerCase(); |
| 345 | const dirName = path.dirname(filePath).toLowerCase(); |
| 346 | let score = 0; |
| 347 | const allWords = query.split(/\s+/).filter((w) => w.length > 0); |
| 348 | if (allWords.length === 0) return 0; |
| 349 | const words = projectNameTokens && projectNameTokens.size > 0 |
| 350 | ? allWords.filter((w) => !projectNameTokens.has(normalizeNameToken(w))) |
| 351 | : allWords; |
| 352 | const scored = words.length > 0 ? words : allWords; |
| 353 | for (const word of scored) { |
| 354 | const subtokens = extractSearchTerms(word, { stems: false }); |
| 355 | if (subtokens.length === 0) continue; |
| 356 | if (subtokens.some((t) => fileName.includes(t))) score += 10; |
| 357 | if (subtokens.some((t) => dirName.includes(t))) score += 5; |
| 358 | else if (subtokens.some((t) => pathLower.includes(t))) score += 3; |
| 359 | } |
| 360 | const queryLower = query.toLowerCase(); |
| 361 | const isTestQuery = queryLower.includes('test') || queryLower.includes('spec'); |
| 362 | if ((!isTestQuery && isTestFile(filePath)) || isDeprioritized === true) score -= 15; |
| 363 | return score; |
| 364 | } |
| 365 | |
| 366 | it('scores every path as before, repeated words and project names included', () => { |
| 367 | const queries = [ |
no test coverage detected