Skip to content

Commit

Permalink
hotfix: only send reuired parameters for search
Browse files Browse the repository at this point in the history
  • Loading branch information
eskombro committed Jun 4, 2020
1 parent 8c3a68b commit af86a99
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions client_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,30 @@ func (c clientSearch) Search(request SearchRequest) (*SearchResponse, error) {
}

values.Add("q", request.Query)
values.Add("filters", request.Filters)
values.Add("offset", strconv.FormatInt(request.Offset, 10))
values.Add("limit", strconv.FormatInt(request.Limit, 10))
values.Add("cropLength", strconv.FormatInt(request.CropLength, 10))
values.Add("attributesToRetrieve", strings.Join(request.AttributesToRetrieve, ","))
values.Add("attributesToCrop", strings.Join(request.AttributesToCrop, ","))
values.Add("attributesToHighlight", strings.Join(request.AttributesToHighlight, ","))
values.Add("matches", strconv.FormatBool(request.Matches))
if request.Filters != "" {
values.Add("filters", request.Filters)
}
if request.Offset != 0 {
values.Add("offset", strconv.FormatInt(request.Offset, 10))
}
if request.Limit != 20 {
values.Add("limit", strconv.FormatInt(request.Limit, 10))
}
if request.CropLength != 0 {
values.Add("cropLength", strconv.FormatInt(request.CropLength, 10))
}
if len(request.AttributesToRetrieve) != 0 {
values.Add("attributesToRetrieve", strings.Join(request.AttributesToRetrieve, ","))
}
if len(request.AttributesToCrop) != 0 {
values.Add("attributesToCrop", strings.Join(request.AttributesToCrop, ","))
}
if len(request.AttributesToHighlight) != 0 {
values.Add("attributesToHighlight", strings.Join(request.AttributesToHighlight, ","))
}
if request.Matches {
values.Add("matches", strconv.FormatBool(request.Matches))
}

req := internalRequest{
endpoint: "/indexes/" + c.indexUID + "/search?" + values.Encode(),
Expand Down

0 comments on commit af86a99

Please sign in to comment.