(text: string)
| 31 | * query "user id" matches an identifier "getUserById" / "user_id". Lowercased. |
| 32 | */ |
| 33 | export function tokenizeForSearch(text: string): string[] { |
| 34 | const out: string[] = []; |
| 35 | // First split on non-alphanumeric, then break camelCase within each piece. |
| 36 | const rawTokens = text.split(/[^A-Za-z0-9]+/).filter(Boolean); |
| 37 | for (const raw of rawTokens) { |
| 38 | out.push(raw.toLowerCase()); |
| 39 | // camelCase / PascalCase → sub-words (getUserById → get, user, by, id) |
| 40 | const camelParts = raw.replace(/([a-z0-9])([A-Z])/g, '$1 $2').split(/\s+/).filter(Boolean); |
| 41 | if (camelParts.length > 1) { |
| 42 | for (const p of camelParts) { |
| 43 | const lower = p.toLowerCase(); |
| 44 | if (lower !== raw.toLowerCase()) out.push(lower); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return out; |
| 49 | } |
| 50 | |
| 51 | // ── BM25 ───────────────────────────────────────────────────────────────────── |
| 52 |
no test coverage detected