Add support for optional LANG param

This commit is contained in:
Timur Garifulin 2021-01-20 00:37:13 +03:00
parent 1cfe7c425f
commit 883b9471ce
5 changed files with 145 additions and 19 deletions

View file

@ -2,12 +2,15 @@ package main
import (
"fmt"
"github.com/expectedsh/go-sonic/sonic"
)
const pswd = "SecretPassword"
func main() {
ingester, err := sonic.NewIngester("localhost", 1491, "SecretPassword")
ingester, err := sonic.NewIngester("localhost", 1491, pswd)
if err != nil {
panic(err)
}
@ -19,14 +22,33 @@ func main() {
{Object: "id:5hg67f8dg5", Text: "Spider man"},
{Object: "id:1m2n3b4vf6", Text: "Batman"},
{Object: "id:68d96h5h9d0", Text: "This is another movie"},
})
}, sonic.LangAutoDetect)
search, err := sonic.NewSearch("localhost", 1491, "SecretPassword")
search, err := sonic.NewSearch("localhost", 1491, pswd)
if err != nil {
panic(err)
}
results, _ := search.Query("movies", "general", "man", 10, 0)
results, _ := search.Query("movies", "general", "man", 10, 0, sonic.LangAutoDetect)
fmt.Println(results)
// Search with LANG set to "none" and "eng"
_ = ingester.FlushCollection("movies")
_ = ingester.BulkPush("movies", "general", 3, []sonic.IngestBulkRecord{
{Object: "id:6ab56b4kk3", Text: "Star wars"},
{Object: "id:5hg67f8dg5", Text: "Spider man"},
{Object: "id:1m2n3b4vf6", Text: "Batman"},
{Object: "id:68d96h5h9d0", Text: "This is another movie"},
}, sonic.LangNone)
results, _ = search.Query("movies", "general", "this is", 10, 0, sonic.LangNone)
fmt.Println(results)
// [id:68d96h5h9d0]
// English stop words should be encountered by Sonic now
results, _ = search.Query("movies", "general", "this is", 10, 0, sonic.LangEng)
fmt.Println(results)
// []
}