feat(parser/keyword): max match count
All checks were successful
submodules sync / sync (push) Successful in 42s
build / build (push) Successful in 1m21s
build / trigger-build-image (push) Successful in 7s

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