Skip to content

Commit

Permalink
TairSearch: add tft.explaincost
Browse files Browse the repository at this point in the history
  • Loading branch information
lyq2333 authored and yangbodong22011 committed Apr 10, 2023
1 parent cad6f5b commit 93a4ada
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tair/taircommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type TairCmdable interface {
TftScanDocIdArgs(ctx context.Context, index string, cursor string, a *TftScanArgs) *redis.SliceCmd
TftAnalyzer(ctx context.Context, analyzerName string, text string) *redis.StringCmd
TftAnalyzerWithArgs(ctx context.Context, analyzerName string, text string, a *TftAnalyzerArgs) *redis.StringCmd
TftExplaincost(ctx context.Context, index string, request string) *redis.StringCmd
TftAddSug(ctx context.Context, index string, textWeight map[string]int64) *redis.IntCmd
TftDelSug(ctx context.Context, index string, text ...string) *redis.IntCmd
TftSugSum(ctx context.Context, index string) *redis.IntCmd
Expand Down
10 changes: 10 additions & 0 deletions tair/tairsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ func (tc tairCmdable) TftAnalyzerWithArgs(ctx context.Context, analyzerName stri
return cmd
}

func (tc tairCmdable) TftExplaincost(ctx context.Context, index string, request string) *redis.StringCmd {
a := make([]interface{}, 3)
a[0] = "TFT.EXPLAINCOST"
a[1] = index
a[2] = request
cmd := redis.NewStringCmd(ctx, a...)
_ = tc(ctx, cmd)
return cmd
}

func (tc tairCmdable) TftAddSug(ctx context.Context, index string, textWeight map[string]int64) *redis.IntCmd {
args := make([]interface{}, 2)
args[0] = "TFT.ADDSUG"
Expand Down
7 changes: 7 additions & 0 deletions tair/tairsearch_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tair_test

import (
"encoding/json"
"github.com/alibaba/tair-go/tair"
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -92,6 +93,12 @@ func (suite *TairSearchTestSuite) TestTftAddDoc() {
assert.NoError(suite.T(), err4)
assert.Equal(suite.T(), result4, "{\"tftkey\":{\"mappings\":{\"_source\":{\"enabled\":true,\"excludes\":[],\"includes\":[]},\"dynamic\":\"false\",\"properties\":{\"f0\":{\"boost\":1.0,\"enabled\":true,\"ignore_above\":-1,\"index\":true,\"similarity\":\"classic\",\"type\":\"text\"},\"f1\":{\"boost\":1.0,\"enabled\":true,\"ignore_above\":-1,\"index\":true,\"similarity\":\"classic\",\"type\":\"text\"}}}}}")

result5, err5 := suite.tairClient.TftExplaincost(ctx, "tftkey", "{\"query\":{\"match\":{\"f1\":\"3\"}}}").Result()
assert.NoError(suite.T(), err5)
var results map[string]interface{}
json.Unmarshal([]byte(result5), &results)
_, ok := results["QUERY_COST"]
assert.Equal(suite.T(), ok, true)
}

func (suite *TairSearchTestSuite) TestTftMSearch() {
Expand Down

0 comments on commit 93a4ada

Please sign in to comment.