diff --git a/search_commands.go b/search_commands.go index 8be39d2a..85e12561 100644 --- a/search_commands.go +++ b/search_commands.go @@ -2090,216 +2090,3 @@ func (c cmdable) FTTagVals(ctx context.Context, index string, field string) *Str _ = c(ctx, cmd) return cmd } - -// TODO: remove FTProfile -// type FTProfileResult struct { -// Results []interface{} -// Profile ProfileDetails -// } - -// type ProfileDetails struct { -// TotalProfileTime string -// ParsingTime string -// PipelineCreationTime string -// Warning string -// IteratorsProfile []IteratorProfile -// ResultProcessorsProfile []ResultProcessorProfile -// } - -// type IteratorProfile struct { -// Type string -// QueryType string -// Time interface{} -// Counter int -// Term string -// Size int -// ChildIterators []IteratorProfile -// } - -// type ResultProcessorProfile struct { -// Type string -// Time interface{} -// Counter int -// } - -// func parseFTProfileResult(data []interface{}) (FTProfileResult, error) { -// var result FTProfileResult -// if len(data) < 2 { -// return result, fmt.Errorf("unexpected data length") -// } - -// // Parse results -// result.Results = data[0].([]interface{}) - -// // Parse profile details -// profileData := data[1].([]interface{}) -// profileDetails := ProfileDetails{} -// for i := 0; i < len(profileData); i += 2 { -// switch profileData[i].(string) { -// case "Total profile time": -// profileDetails.TotalProfileTime = profileData[i+1].(string) -// case "Parsing time": -// profileDetails.ParsingTime = profileData[i+1].(string) -// case "Pipeline creation time": -// profileDetails.PipelineCreationTime = profileData[i+1].(string) -// case "Warning": -// profileDetails.Warning = profileData[i+1].(string) -// case "Iterators profile": -// profileDetails.IteratorsProfile = parseIteratorsProfile(profileData[i+1].([]interface{})) -// case "Result processors profile": -// profileDetails.ResultProcessorsProfile = parseResultProcessorsProfile(profileData[i+1].([]interface{})) -// } -// } - -// result.Profile = profileDetails -// return result, nil -// } - -// func parseIteratorsProfile(data []interface{}) []IteratorProfile { -// var iterators []IteratorProfile -// for _, item := range data { -// profile := item.([]interface{}) -// iterator := IteratorProfile{} -// for i := 0; i < len(profile); i += 2 { -// switch profile[i].(string) { -// case "Type": -// iterator.Type = profile[i+1].(string) -// case "Query type": -// iterator.QueryType = profile[i+1].(string) -// case "Time": -// iterator.Time = profile[i+1] -// case "Counter": -// iterator.Counter = int(profile[i+1].(int64)) -// case "Term": -// iterator.Term = profile[i+1].(string) -// case "Size": -// iterator.Size = int(profile[i+1].(int64)) -// case "Child iterators": -// iterator.ChildIterators = parseChildIteratorsProfile(profile[i+1].([]interface{})) -// } -// } -// iterators = append(iterators, iterator) -// } -// return iterators -// } - -// func parseChildIteratorsProfile(data []interface{}) []IteratorProfile { -// var iterators []IteratorProfile -// for _, item := range data { -// profile := item.([]interface{}) -// iterator := IteratorProfile{} -// for i := 0; i < len(profile); i += 2 { -// switch profile[i].(string) { -// case "Type": -// iterator.Type = profile[i+1].(string) -// case "Query type": -// iterator.QueryType = profile[i+1].(string) -// case "Time": -// iterator.Time = profile[i+1] -// case "Counter": -// iterator.Counter = int(profile[i+1].(int64)) -// case "Term": -// iterator.Term = profile[i+1].(string) -// case "Size": -// iterator.Size = int(profile[i+1].(int64)) -// } -// } -// iterators = append(iterators, iterator) -// } -// return iterators -// } - -// func parseResultProcessorsProfile(data []interface{}) []ResultProcessorProfile { -// var processors []ResultProcessorProfile -// for _, item := range data { -// profile := item.([]interface{}) -// processor := ResultProcessorProfile{} -// for i := 0; i < len(profile); i += 2 { -// switch profile[i].(string) { -// case "Type": -// processor.Type = profile[i+1].(string) -// case "Time": -// processor.Time = profile[i+1] -// case "Counter": -// processor.Counter = int(profile[i+1].(int64)) -// } -// } -// processors = append(processors, processor) -// } -// return processors -// } - -// func NewFTProfileCmd(ctx context.Context, args ...interface{}) *FTProfileCmd { -// return &FTProfileCmd{ -// baseCmd: baseCmd{ -// ctx: ctx, -// args: args, -// }, -// } -// } - -// type FTProfileCmd struct { -// baseCmd -// val FTProfileResult -// } - -// func (cmd *FTProfileCmd) String() string { -// return cmdString(cmd, cmd.val) -// } - -// func (cmd *FTProfileCmd) SetVal(val FTProfileResult) { -// cmd.val = val -// } - -// func (cmd *FTProfileCmd) Result() (FTProfileResult, error) { -// return cmd.val, cmd.err -// } - -// func (cmd *FTProfileCmd) Val() FTProfileResult { -// return cmd.val -// } - -// func (cmd *FTProfileCmd) readReply(rd *proto.Reader) (err error) { -// data, err := rd.ReadSlice() -// if err != nil { -// return err -// } -// cmd.val, err = parseFTProfileResult(data) -// if err != nil { -// cmd.err = err -// } -// return nil -// } - -// // FTProfile - Executes a search query and returns a profile of how the query was processed. -// // The 'index' parameter specifies the index to search, the 'limited' parameter specifies whether to limit the results, -// // and the 'query' parameter specifies the search / aggreagte query. Please notice that you must either pass a SearchQuery or an AggregateQuery. -// // For more information, please refer to the Redis documentation: -// // [FT.PROFILE]: (https://redis.io/commands/ft.profile/) -// func (c cmdable) FTProfile(ctx context.Context, index string, limited bool, query interface{}) *FTProfileCmd { -// queryType := "" -// var argsQuery []interface{} - -// switch v := query.(type) { -// case AggregateQuery: -// queryType = "AGGREGATE" -// argsQuery = v -// case SearchQuery: -// queryType = "SEARCH" -// argsQuery = v -// default: -// panic("FT.PROFILE: query must be either AggregateQuery or SearchQuery") -// } - -// args := []interface{}{"FT.PROFILE", index, queryType} - -// if limited { -// args = append(args, "LIMITED") -// } -// args = append(args, "QUERY") -// args = append(args, argsQuery...) - -// cmd := NewFTProfileCmd(ctx, args...) -// _ = c(ctx, cmd) -// return cmd -// } diff --git a/search_test.go b/search_test.go index 4359b02f..4d8417d7 100644 --- a/search_test.go +++ b/search_test.go @@ -1694,96 +1694,6 @@ func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []str Expect(result.Total).To(BeEquivalentTo(len(expectedDocIDs))) } -// It("should FTProfile Search and Aggregate", Label("search", "ftprofile"), func() { -// val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "t", FieldType: redis.SearchFieldTypeText}).Result() -// Expect(err).NotTo(HaveOccurred()) -// Expect(val).To(BeEquivalentTo("OK")) -// WaitForIndexing(client, "idx1") - -// client.HSet(ctx, "1", "t", "hello") -// client.HSet(ctx, "2", "t", "world") - -// // FTProfile Search -// query := redis.FTSearchQuery("hello|world", &redis.FTSearchOptions{NoContent: true}) -// res1, err := client.FTProfile(ctx, "idx1", false, query).Result() -// Expect(err).NotTo(HaveOccurred()) -// panic(res1) -// Expect(len(res1["results"].([]interface{}))).To(BeEquivalentTo(3)) -// resProfile := res1["profile"].(map[interface{}]interface{}) -// Expect(resProfile["Parsing time"].(float64) < 0.5).To(BeTrue()) -// iterProfile0 := resProfile["Iterators profile"].([]interface{})[0].(map[interface{}]interface{}) -// Expect(iterProfile0["Counter"]).To(BeEquivalentTo(2.0)) -// Expect(iterProfile0["Type"]).To(BeEquivalentTo("UNION")) - -// // FTProfile Aggregate -// aggQuery := redis.FTAggregateQuery("*", &redis.FTAggregateOptions{ -// Load: []redis.FTAggregateLoad{{Field: "t"}}, -// Apply: []redis.FTAggregateApply{{Field: "startswith(@t, 'hel')", As: "prefix"}}}) -// res2, err := client.FTProfile(ctx, "idx1", false, aggQuery).Result() -// Expect(err).NotTo(HaveOccurred()) -// Expect(len(res2["results"].([]interface{}))).To(BeEquivalentTo(2)) -// resProfile = res2["profile"].(map[interface{}]interface{}) -// iterProfile0 = resProfile["Iterators profile"].([]interface{})[0].(map[interface{}]interface{}) -// Expect(iterProfile0["Counter"]).To(BeEquivalentTo(2)) -// Expect(iterProfile0["Type"]).To(BeEquivalentTo("WILDCARD")) -// }) - -// It("should FTProfile Search Limited", Label("search", "ftprofile"), func() { -// val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "t", FieldType: redis.SearchFieldTypeText}).Result() -// Expect(err).NotTo(HaveOccurred()) -// Expect(val).To(BeEquivalentTo("OK")) -// WaitForIndexing(client, "idx1") - -// client.HSet(ctx, "1", "t", "hello") -// client.HSet(ctx, "2", "t", "hell") -// client.HSet(ctx, "3", "t", "help") -// client.HSet(ctx, "4", "t", "helowa") - -// // FTProfile Search -// query := redis.FTSearchQuery("%hell% hel*", &redis.FTSearchOptions{}) -// res1, err := client.FTProfile(ctx, "idx1", true, query).Result() -// Expect(err).NotTo(HaveOccurred()) -// resProfile := res1["profile"].(map[interface{}]interface{}) -// iterProfile0 := resProfile["Iterators profile"].([]interface{})[0].(map[interface{}]interface{}) -// Expect(iterProfile0["Type"]).To(BeEquivalentTo("INTERSECT")) -// Expect(len(res1["results"].([]interface{}))).To(BeEquivalentTo(3)) -// Expect(iterProfile0["Child iterators"].([]interface{})[0].(map[interface{}]interface{})["Child iterators"]).To(BeEquivalentTo("The number of iterators in the union is 3")) -// Expect(iterProfile0["Child iterators"].([]interface{})[1].(map[interface{}]interface{})["Child iterators"]).To(BeEquivalentTo("The number of iterators in the union is 4")) -// }) - -// It("should FTProfile Search query params", Label("search", "ftprofile"), func() { -// hnswOptions := &redis.FTHNSWOptions{Type: "FLOAT32", Dim: 2, DistanceMetric: "L2"} -// val, err := client.FTCreate(ctx, "idx1", -// &redis.FTCreateOptions{}, -// &redis.FieldSchema{FieldName: "v", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptions}}).Result() -// Expect(err).NotTo(HaveOccurred()) -// Expect(val).To(BeEquivalentTo("OK")) -// WaitForIndexing(client, "idx1") - -// client.HSet(ctx, "a", "v", "aaaaaaaa") -// client.HSet(ctx, "b", "v", "aaaabaaa") -// client.HSet(ctx, "c", "v", "aaaaabaa") - -// // FTProfile Search -// searchOptions := &redis.FTSearchOptions{ -// Return: []redis.FTSearchReturn{{FieldName: "__v_score"}}, -// SortBy: []redis.FTSearchSortBy{{FieldName: "__v_score", Asc: true}}, -// DialectVersion: 2, -// Params: map[string]interface{}{"vec": "aaaaaaaa"}, -// } -// query := redis.FTSearchQuery("*=>[KNN 2 @v $vec]", searchOptions) -// res1, err := client.FTProfile(ctx, "idx1", false, query).Result() -// Expect(err).NotTo(HaveOccurred()) -// resProfile := res1["profile"].(map[interface{}]interface{}) -// iterProfile0 := resProfile["Iterators profile"].([]interface{})[0].(map[interface{}]interface{}) -// Expect(iterProfile0["Counter"]).To(BeEquivalentTo(2)) -// Expect(iterProfile0["Type"]).To(BeEquivalentTo(redis.SearchFieldTypeVector.String())) -// Expect(res1["total_results"]).To(BeEquivalentTo(2)) -// results0 := res1["results"].([]interface{})[0].(map[interface{}]interface{}) -// Expect(results0["id"]).To(BeEquivalentTo("a")) -// Expect(results0["extra_attributes"].(map[interface{}]interface{})["__v_score"]).To(BeEquivalentTo("0")) -// }) - var _ = Describe("RediSearch FT.Config with Resp2 and Resp3", Label("search", "NonRedisEnterprise"), func() { var clientResp2 *redis.Client