* Score an entry against a query. Higher = more relevant. * Heuristic: each matched keyword = 1 point. Heading match = +2 bonus. * Filename match = +1 bonus.
(entry, queryTokens)
| 174 | * Filename match = +1 bonus. |
| 175 | */ |
| 176 | _scoreEntry(entry, queryTokens) { |
| 177 | if (queryTokens.length === 0) return 0; |
| 178 | let score = 0; |
| 179 | const querySet = new Set(queryTokens); |
| 180 | for (const kw of entry.keywords) { |
| 181 | if (querySet.has(kw)) score += 1; |
| 182 | } |
| 183 | if (entry.heading) { |
| 184 | const headTokens = this._tokenize(entry.heading); |
| 185 | for (const t of headTokens) if (querySet.has(t)) score += 2; |
| 186 | } |
| 187 | if (querySet.has(entry.name.toLowerCase())) score += 1; |
| 188 | return score; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Pick the most relevant knowledge notes for the given query, fitting under |
no test coverage detected