feat(parser/keyword): max match count

This commit is contained in:
张泊明518370910136 2024-11-01 03:31:04 -04:00
parent 5de4c3ee78
commit 03c2819d25
GPG Key ID: D47306D7062CDA9D

View File

@ -8,8 +8,9 @@ import (
) )
type Match struct { type Match struct {
Keyword string Keyword string
Score int Score int
MaxMatchCount int
} }
type Conf struct { type Conf struct {
@ -33,6 +34,9 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) (
content := executorResult.Files[file] content := executorResult.Files[file]
for _, match := range conf.Matches { for _, match := range conf.Matches {
count := strings.Count(content, match.Keyword) count := strings.Count(content, match.Keyword)
if match.MaxMatchCount > 0 {
count = min(count, match.MaxMatchCount)
}
if count > 0 { if count > 0 {
matched = true matched = true
score -= count * match.Score score -= count * match.Score