feat(parser/keyword): max match count
This commit is contained in:
parent
5de4c3ee78
commit
03c2819d25
|
@ -10,6 +10,7 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user