photoprism/pkg/txt/keywords.go
Michael Mayer f8a45b14d9 Backend: Move reusable packages to pkg/
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-01-12 14:00:56 +01:00

24 lines
421 B
Go

package txt
import (
"regexp"
"strings"
)
var KeywordsRegexp = regexp.MustCompile("[\\p{L}]{3,}")
// Keywords extracts keywords for indexing and returns them as string slice.
func Keywords(s string) (results []string) {
all := KeywordsRegexp.FindAllString(s, -1)
for _, w := range all {
w = strings.ToLower(w)
if _, ok := Stopwords[w]; ok == false {
results = append(results, w)
}
}
return results
}