fuzzyMatch 模糊匹配
(content, query string)
| 212 | |
| 213 | // fuzzyMatch 模糊匹配 |
| 214 | func fuzzyMatch(content, query string) float64 { |
| 215 | queryWords := strings.Fields(query) |
| 216 | if len(queryWords) == 0 { |
| 217 | return 0.0 |
| 218 | } |
| 219 | |
| 220 | matchedWords := 0 |
| 221 | for _, word := range queryWords { |
| 222 | if strings.Contains(content, word) { |
| 223 | matchedWords++ |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return float64(matchedWords) / float64(len(queryWords)) |
| 228 | } |
| 229 | |
| 230 | // generateSnippet 生成摘要片段 |
| 231 | func generateSnippet(content, query string, maxLen int) string { |