(query: string, text: string)
| 1614 | } |
| 1615 | |
| 1616 | function scoreMatch(query: string, text: string): number { |
| 1617 | if (!query) return 1 |
| 1618 | if (!text) return 0 |
| 1619 | const q = query.toLowerCase() |
| 1620 | const t = text.toLowerCase() |
| 1621 | if (t === q) return 1000 |
| 1622 | if (t.startsWith(q)) return 900 - t.length * 0.5 |
| 1623 | const wordBoundary = new RegExp(`(?:^|[\\s·:_\\-/])${escapeRegex(q)}`) |
| 1624 | if (wordBoundary.test(t)) return 700 - t.length * 0.5 |
| 1625 | if (t.includes(q)) return 500 - t.length * 0.5 |
| 1626 | |
| 1627 | let i = 0 |
| 1628 | let gaps = 0 |
| 1629 | let prev = -1 |
| 1630 | for (let j = 0; j < t.length && i < q.length; j++) { |
| 1631 | if (t[j] === q[i]) { |
| 1632 | if (prev === -1) gaps += j |
| 1633 | else gaps += j - prev - 1 |
| 1634 | prev = j |
| 1635 | i++ |
| 1636 | } |
| 1637 | } |
| 1638 | if (i === q.length) return Math.max(1, 200 - gaps * 3 - t.length * 0.2) |
| 1639 | return 0 |
| 1640 | } |
| 1641 | |
| 1642 | function firstMatchColumn(query: string, text: string): number { |
| 1643 | const q = query.trim().toLowerCase() |
no test coverage detected