| 79 | } |
| 80 | |
| 81 | func SearchPoints(collectionName string, pointSearchRequest PointSearchRequest) (res []SearchResult, err error) { |
| 82 | response := &CommonResponse{} |
| 83 | var reqBytes []byte |
| 84 | reqBytes, err = json.Marshal(pointSearchRequest) |
| 85 | if err != nil { |
| 86 | common.Logger.Error(err.Error()) |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | body, err := Send(http.MethodPost, collectionApi+"/"+collectionName+pointsApi+searchApi, reqBytes) |
| 91 | if err != nil { |
| 92 | common.Logger.Error(err.Error()) |
| 93 | return |
| 94 | } |
| 95 | |
| 96 | err = json.Unmarshal(body, &response) |
| 97 | if err != nil { |
| 98 | common.Logger.Error(err.Error()) |
| 99 | return |
| 100 | } |
| 101 | if response.Result == nil { |
| 102 | return res, errors.New(response.Status.(map[string]interface{})["error"].(string)) |
| 103 | } |
| 104 | list := response.Result.([]interface{}) |
| 105 | for _, v := range list { |
| 106 | sr := SearchResult{} |
| 107 | err = mapstructure.Decode(v, &sr) |
| 108 | if err != nil { |
| 109 | common.Logger.Error(err.Error()) |
| 110 | return |
| 111 | } |
| 112 | res = append(res, sr) |
| 113 | } |
| 114 | return |
| 115 | |
| 116 | } |