-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Embedder.URL * feat: add gzip and deflate encoding * feat: client support content encoding for body and response * feat: add option for enable content encoding * feat: add content encoding and compress level type * feat: add content encoding on constructor * fix: header set for user agent * feat: add brotli encoding * fix: support request and response encoding same type encoding opt * fix: add unit test for options * feat: Add experimental features support The code changes introduce a new `ExperimentalFeatures` struct and methods to support experimental features * generating type marshalers and unmarshalers * add: zero allocation copy for writer * add: unit test for zero allocation copy * feat: transcode get and update curl to golang example on code-samples file * fix: remove encoding option on internal request object * chore: add unit test for content encoding * fix: used built-in flate package * fix: used built-in gzip package * fix: data race on test zero alloc * fix: test case issue * fix: add some test stage for improve coverage * fix: remove brotli test stage * fix: add encoder for decoing encoded internal error * fix: currntly support delfate compression by using zlib * fix: add writer nil error on test for prevent panic * Add multi-search federation (fixes #573) * feat: Add experimental features support The code changes introduce a new `ExperimentalFeatures` struct and methods to support experimental features * feat: transcode get and update curl to golang example on code-samples file * feat: Add support for EditDocumentsByFunction and ContainsFilter in ExperimentalFeatures --------- Co-authored-by: polyfloyd <floyd@polyfloyd.net> Co-authored-by: Javad <ja7ad@live.com> Co-authored-by: meili-bors[bot] <89034592+meili-bors[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2ee4206
commit 1cd56a5
Showing
6 changed files
with
500 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// Type for experimental features with additional client field | ||
type ExperimentalFeatures struct { | ||
client *client | ||
ExperimentalFeaturesBase | ||
} | ||
|
||
func (m *meilisearch) ExperimentalFeatures() *ExperimentalFeatures { | ||
return &ExperimentalFeatures{client: m.client} | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetVectorStore(vectorStore bool) *ExperimentalFeatures { | ||
ef.VectorStore = &vectorStore | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetLogsRoute(logsRoute bool) *ExperimentalFeatures { | ||
ef.LogsRoute = &logsRoute | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetMetrics(metrics bool) *ExperimentalFeatures { | ||
ef.Metrics = &metrics | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetEditDocumentsByFunction(editDocumentsByFunction bool) *ExperimentalFeatures { | ||
ef.EditDocumentsByFunction = &editDocumentsByFunction | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetContainsFilter(containsFilter bool) *ExperimentalFeatures { | ||
ef.ContainsFilter = &containsFilter | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Get() (*ExperimentalFeaturesResult, error) { | ||
return ef.GetWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) GetWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: &resp, | ||
withQueryParams: map[string]string{}, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "GetExperimentalFeatures", | ||
} | ||
|
||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Update() (*ExperimentalFeaturesResult, error) { | ||
return ef.UpdateWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) UpdateWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
request := ExperimentalFeaturesBase{ | ||
VectorStore: ef.VectorStore, | ||
LogsRoute: ef.LogsRoute, | ||
Metrics: ef.Metrics, | ||
EditDocumentsByFunction: ef.EditDocumentsByFunction, | ||
ContainsFilter: ef.ContainsFilter, | ||
} | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodPatch, | ||
contentType: contentTypeJSON, | ||
withRequest: request, | ||
withResponse: resp, | ||
withQueryParams: nil, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "UpdateExperimentalFeatures", | ||
} | ||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGet_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestGetStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestGetStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
gotResp, err := ef.Get() | ||
require.NoError(t, err) | ||
require.NotNil(t, gotResp, "ExperimentalFeatures.Get() should not return nil value") | ||
}) | ||
} | ||
} | ||
|
||
func TestUpdate_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestUpdateStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestUpdateStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
ef.SetVectorStore(true) | ||
ef.SetLogsRoute(true) | ||
ef.SetMetrics(true) | ||
ef.SetEditDocumentsByFunction(true) | ||
ef.SetContainsFilter(true) | ||
gotResp, err := ef.Update() | ||
require.NoError(t, err) | ||
require.Equal(t, true, gotResp.VectorStore, "ExperimentalFeatures.Update() should return vectorStore as true") | ||
require.Equal(t, true, gotResp.LogsRoute, "ExperimentalFeatures.Update() should return logsRoute as true") | ||
require.Equal(t, true, gotResp.Metrics, "ExperimentalFeatures.Update() should return metrics as true") | ||
require.Equal(t, true, gotResp.EditDocumentsByFunction, "ExperimentalFeatures.Update() should return editDocumentsByFunction as true") | ||
require.Equal(t, true, gotResp.ContainsFilter, "ExperimentalFeatures.Update() should return containsFilter as true") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.