From 03c2819d25250bc4befba71285667cf36c57704b Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Fri, 1 Nov 2024 03:31:04 -0400 Subject: [PATCH] feat(parser/keyword): max match count --- internal/parser/keyword/parser.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/parser/keyword/parser.go b/internal/parser/keyword/parser.go index d6467e5..78a4cc6 100644 --- a/internal/parser/keyword/parser.go +++ b/internal/parser/keyword/parser.go @@ -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