Hi,
I have a simple Testscript for Go Client Library v2:
package main
// test couchbase library v2
import (
“fmt”
“time”
gocb "github.com/couchbase/gocb/v2"
"github.com/couchbase/gocb/v2/search"
)
type result struct {
Type string
ID int
ContentName string
}
func main() {
// -----------------
// connect database
// -----------------
cluster, err := gocb.Connect(
"localhost",
gocb.ClusterOptions{
Username: "test",
Password: "test",
})
if err != nil {
panic(err)
}
// -----------------
// get fts result
// -----------------
searchIndex := "ftsde" // search over both language indices for id search
f := []search.Query{}
f = append(f, search.NewMatchQuery("test").Analyzer("test").Field("title"))
cq := search.NewConjunctionQuery(f...)
start := time.Now()
matchResult, err := cluster.SearchQuery(
searchIndex,
cq,
&gocb.SearchOptions{
Limit: 10,
},
)
if err != nil {
panic(err)
}
for matchResult.Next() {
row := matchResult.Row()
fmt.Printf("Document ID: %s, search score: %f\n", row.ID, row.Score)
}
err = matchResult.Err()
if err != nil {
panic(err)
}
elapsed := time.Since(start)
fmt.Println(elapsed)
// metadata of search.
searchMetadata, err := matchResult.MetaData()
if err != nil {
panic(err)
}
fmt.Printf("%+v", searchMetadata.Metrics)
}
Result is:
Document ID: 15440904043944, search score: 5.645592
Document ID: 16032810983964, search score: 3.992036
Document ID: 15476322019054, search score: 2.987216
Document ID: 15476510453196, search score: 2.790567
Document ID: 15572179807867, search score: 2.692715
Document ID: 15571809006779, search score: 2.692715
Document ID: 15440907233320, search score: 2.651288
Document ID: 15476322187663, search score: 2.651288
Document ID: 15476504417609, search score: 2.651288
Document ID: 15480642954771, search score: 2.524786
8.049201ms
{Took:150.237ms TotalRows:41 MaxScore:5.645592100487007 TotalPartitionCount:0 SuccessPartitionCount:0 ErrorPartitionCount:0}
You see, Metrics shows a much slower query time than the whole execution time measured in go.
So I think Took() from Metrics can not be valid. I think that should be μs (microseconds) instead of ms (milliseconds). Go Library v1 shows in metrics also about 1’000 times faster results, so I think there is something wrong in v2. Or is there something that I do wrong?
Thanks, Pascal