Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "github.com/couchbase/gocb"
- "fmt"
- "github.com/couchbase/gocb/cbft"
- )
- type User struct {
- Id string `json:"uid"`
- Email string `json:"email"`
- Interests []string `json:"interests"`
- }
- func main() {
- cluster, _ := gocb.Connect("couchbase://172.23.120.18")
- cluster.Authenticate(gocb.PasswordAuthenticator{
- Username: "Administrator",
- Password: "password",
- })
- bucket, _ := cluster.OpenBucket("default", "")
- /*bucket.Insert("key1", nil, 0)
- bucket.Insert("key2", User{
- Id: "kingarthur",
- Email: "kingarthur@couchbase.com",
- Interests: []string{"Holy Grail", "African Swallows"},
- }, 0)
- */
- ftsIndexName := "ftsIndex"
- //ftsIndexName := "travel-index"
- //term := fmt.Sprintf("SampleValue%d", 1)
- term := fmt.Sprintf("SampleValue1")
- //term := fmt.Sprintf("office")
- query := gocb.NewSearchQuery(ftsIndexName, cbft.NewTermQuery(term))
- res, err := bucket.ExecuteSearchQuery(query)
- if err != nil {
- fmt.Printf("Err:%s", err)
- }
- for _, hit := range res.Hits() {
- fmt.Printf("hit:%s\n", hit.Id)
- }
- if res.Errors != nil || res.Status().Total != 1 {
- if res.Errors != nil {
- for err := range res.Errors() {
- fmt.Printf("Err:%s", err)
- }
- }
- if len(res.Hits()) != 1 {
- fmt.Printf("Err:Hits=%d", res.Status().Total)
- }
- return
- }
- }
Add Comment
Please, Sign In to add comment