(text: string, query: string)
| 70 | } |
| 71 | |
| 72 | function extractSnippet(text: string, query: string): string { |
| 73 | const lower = text.toLowerCase(); |
| 74 | const pos = lower.indexOf(query.toLowerCase().split(/\s+/)[0]); |
| 75 | if (pos < 0) return text.slice(0, 120) + (text.length > 120 ? "…" : ""); |
| 76 | const start = Math.max(0, pos - 40); |
| 77 | const end = Math.min(text.length, pos + 80); |
| 78 | return (start > 0 ? "…" : "") + text.slice(start, end) + (end < text.length ? "…" : ""); |
| 79 | } |
| 80 | |
| 81 | function query( |
| 82 | q: string, |