Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions index_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func TestIndex_SearchOnNestedFileds(t *testing.T) {
map[string]interface{}{
"id": float64(5), "title": "The Hobbit",
"info": map[string]interface{}{
"comment": "An awesome book",
"comment": "An awesome book",
"reviewNb": float64(900),
},
},
Expand All @@ -969,7 +969,7 @@ func TestIndex_SearchOnNestedFileds(t *testing.T) {
map[string]interface{}{
"id": float64(5), "title": "The Hobbit",
"info": map[string]interface{}{
"comment": "An awesome book",
"comment": "An awesome book",
"reviewNb": float64(900),
},
},
Expand All @@ -993,14 +993,14 @@ func TestIndex_SearchOnNestedFileds(t *testing.T) {
map[string]interface{}{
"id": float64(2), "title": "Le Petit Prince",
"info": map[string]interface{}{
"comment": "A french book",
"comment": "A french book",
"reviewNb": float64(600),
},
},
map[string]interface{}{
"id": float64(3), "title": "Le Rouge et le Noir",
"info": map[string]interface{}{
"comment": "Another french book",
"comment": "Another french book",
"reviewNb": float64(700),
},
},
Expand All @@ -1027,7 +1027,7 @@ func TestIndex_SearchOnNestedFileds(t *testing.T) {
map[string]interface{}{
"id": float64(5), "title": "The Hobbit",
"info": map[string]interface{}{
"comment": "An awesome book",
"comment": "An awesome book",
"reviewNb": float64(900),
},
},
Expand Down Expand Up @@ -1061,7 +1061,7 @@ func TestIndex_SearchOnNestedFileds(t *testing.T) {
map[string]interface{}{
"id": float64(5), "title": "The Hobbit",
"info": map[string]interface{}{
"comment": "An awesome book",
"comment": "An awesome book",
"reviewNb": float64(900),
},
},
Expand Down
49 changes: 49 additions & 0 deletions index_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,52 @@ func (i Index) ResetSortableAttributes() (resp *Task, err error) {
}
return resp, nil
}

func (i Index) GetTypoTolerance() (resp *TypoTolerance, err error) {
resp = &TypoTolerance{}
req := internalRequest{
endpoint: "/indexes/" + i.UID + "/settings/typo-tolerance",
method: http.MethodGet,
withRequest: nil,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusOK},
functionName: "GetTypoTolerance",
}
if err := i.client.executeRequest(req); err != nil {
return nil, err
}
return resp, nil
}

func (i Index) UpdateTypoTolerance(request *TypoTolerance) (resp *Task, err error) {
resp = &Task{}
req := internalRequest{
endpoint: "/indexes/" + i.UID + "/settings/typo-tolerance",
method: http.MethodPost,
contentType: contentTypeJSON,
withRequest: &request,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you enlighten me on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object doesn't really exist in go, so to send multiple arguments it's easier to use struct. For this purpose, we create this struct with all data we need to process a request:

type internalRequest struct {
	endpoint    string
	method      string
	contentType string

	withRequest     interface{}
	withResponse    interface{}
	withQueryParams map[string]string

	acceptedStatusCodes []int

	functionName string
}

We send the struct to the eexecuteRequestfunction with all the data needed, and ainterface{}inwithRequest` who will be fill with the response from the API.

withResponse: resp,
acceptedStatusCodes: []int{http.StatusAccepted},
functionName: "UpdateTypoTolerance",
}
if err := i.client.executeRequest(req); err != nil {
return nil, err
}
return resp, nil
}

func (i Index) ResetTypoTolerance() (resp *Task, err error) {
resp = &Task{}
req := internalRequest{
endpoint: "/indexes/" + i.UID + "/settings/typo-tolerance",
method: http.MethodDelete,
withRequest: nil,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusAccepted},
functionName: "ResetTypoTolerance",
}
if err := i.client.executeRequest(req); err != nil {
return nil, err
}
return resp, nil
}
Loading