Golang implementation of Aho-Corasick algorithm, working on redis
- Refered to project : judou/redis-ac-keyword
- Aho-Corasick algorithm's paper link : Efficient string matching: an aid to bibliographic search
- Aho-Corasick Wikipedia : Aho-Corasick algorithm wiki
- Golang 1.7+
- Redis 3.x+
- (Optional) Docker
If there is no redis docker image, import the image and run the docker container.
$ sh run-redis.sh
package main
import (
"fmt"
"github.com/skyoo2003/acor"
)
func main() {
args := &acor.AhoCorasickArgs{
Addr: "localhost:6379",
Password: "",
DB: 0,
Name: "sample",
}
ac := acor.Create(args)
defer ac.Close()
keywords := []string{"he", "her", "him"}
for _, k := range keywords {
ac.Add(k)
}
matched := ac.Find("he is him")
fmt.Println(matched)
ac.Flush() // If you want to remove all of data
}
If you want to participate, you can create an issue or request a 'Pull Request'.
Welcome any and all suggestions.
MIT License