fuzzyMatchTasks scores all tasks against query, filters by threshold, and returns top 5.
(query string, tasks []*model.Task, threshold float64)
| 249 | |
| 250 | // fuzzyMatchTasks scores all tasks against query, filters by threshold, and returns top 5. |
| 251 | func fuzzyMatchTasks(query string, tasks []*model.Task, threshold float64) []fuzzyMatch { |
| 252 | var matches []fuzzyMatch |
| 253 | for _, t := range tasks { |
| 254 | score := bestFuzzyScore(query, t) |
| 255 | if score >= threshold { |
| 256 | matches = append(matches, fuzzyMatch{Task: t, Score: score}) |
| 257 | } |
| 258 | } |
| 259 | sort.Slice(matches, func(i, j int) bool { |
| 260 | return matches[i].Score > matches[j].Score |
| 261 | }) |
| 262 | const maxResults = 5 |
| 263 | if len(matches) > maxResults { |
| 264 | matches = matches[:maxResults] |
| 265 | } |
| 266 | return matches |
| 267 | } |
| 268 | |
| 269 | // bestFuzzyScore returns the best similarity score between query and the task's ID or title. |
| 270 | func bestFuzzyScore(query string, task *model.Task) float64 { |