ai_xiaopei
2026-07-25 beb1530ffd6ef2f505acc2bc8809599fbae30c0a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package search
 
import (
    "strings"
)
 
// GenericWords 通用词列表(降低权重避免匹配所有文件)
var GenericWords = []string{
    "问题", "故障", "报错", "异常", "无法", "不能",
    "怎么", "如何", "为什么", "是什么", "哪里", "什么",
    "可以", "需要", "应该", "是否", "有没有",
}
 
// IsGenericWord 判断是否为通用词
func IsGenericWord(word string) bool {
    word = strings.ToLower(word)
    for _, g := range GenericWords {
        if word == g {
            return true
        }
    }
    return false
}
 
// ScoreType 评分类型
type ScoreType int
 
const (
    ScoreNormal  ScoreType = iota // 普通词
    ScoreExpanded                 // 扩展词
    ScoreSymptom                  // 症状词
)
 
// ScoreTable 评分表
var ScoreTable = map[ScoreType]map[string]int{
    ScoreNormal: {
        "path":    2,
        "title":   3,
        "tag":     2,
        "content": 1,
    },
    ScoreExpanded: {
        "path":    40,
        "title":   30,
        "tag":     20,
        "content": 5,
    },
    ScoreSymptom: {
        "path":    60,
        "title":   50,
        "tag":     35,
        "content": 15,
    },
}
 
// CalcScore 计算单个关键词在某个位置的得分
func CalcScore(keyword string, position string, scoreType ScoreType) int {
    base := ScoreTable[scoreType][position]
    if base == 0 {
        return 0
    }
    if IsGenericWord(keyword) {
        return base / 10 // 通用词降权
    }
    return base
}