Skip to content

Commit 1cd56a5

Browse files
A7baripolyfloydja7admeili-bors[bot]
authored
Support experimental manager (#572)
* 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 <[email protected]> Co-authored-by: Javad <[email protected]> Co-authored-by: meili-bors[bot] <89034592+meili-bors[bot]@users.noreply.github.com>
1 parent 2ee4206 commit 1cd56a5

File tree

6 files changed

+500
-56
lines changed

6 files changed

+500
-56
lines changed

.code-samples.meilisearch.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ multi_search_1: |-
100100
},
101101
},
102102
})
103+
get_experimental_features_1: |-
104+
client.ExperimentalFeatures().Get()
105+
update_experimental_features_1: |-
106+
client.ExperimentalFeatures().SetMetrics(true).Update()
103107
facet_search_1: |-
104108
client.Index("books").FacetSearch(&meilisearch.FacetSearchRequest{
105109
FacetQuery: "fiction",
@@ -919,7 +923,7 @@ update_separator_tokens_1: |-
919923
"&hellip;",
920924
})
921925
reset_separator_tokens_1: |-
922-
client.Index("articles").ResetSeparatorTokens()
926+
client.Index("articles").ResetSeparatorTokens()
923927
get_non_separator_tokens_1: |-
924928
client.Index("articles").GetNonSeparatorTokens()
925929
update_non_separator_tokens_1: |-

features.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package meilisearch
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// Type for experimental features with additional client field
9+
type ExperimentalFeatures struct {
10+
client *client
11+
ExperimentalFeaturesBase
12+
}
13+
14+
func (m *meilisearch) ExperimentalFeatures() *ExperimentalFeatures {
15+
return &ExperimentalFeatures{client: m.client}
16+
}
17+
18+
func (ef *ExperimentalFeatures) SetVectorStore(vectorStore bool) *ExperimentalFeatures {
19+
ef.VectorStore = &vectorStore
20+
return ef
21+
}
22+
23+
func (ef *ExperimentalFeatures) SetLogsRoute(logsRoute bool) *ExperimentalFeatures {
24+
ef.LogsRoute = &logsRoute
25+
return ef
26+
}
27+
28+
func (ef *ExperimentalFeatures) SetMetrics(metrics bool) *ExperimentalFeatures {
29+
ef.Metrics = &metrics
30+
return ef
31+
}
32+
33+
func (ef *ExperimentalFeatures) SetEditDocumentsByFunction(editDocumentsByFunction bool) *ExperimentalFeatures {
34+
ef.EditDocumentsByFunction = &editDocumentsByFunction
35+
return ef
36+
}
37+
38+
func (ef *ExperimentalFeatures) SetContainsFilter(containsFilter bool) *ExperimentalFeatures {
39+
ef.ContainsFilter = &containsFilter
40+
return ef
41+
}
42+
43+
func (ef *ExperimentalFeatures) Get() (*ExperimentalFeaturesResult, error) {
44+
return ef.GetWithContext(context.Background())
45+
}
46+
47+
func (ef *ExperimentalFeatures) GetWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) {
48+
resp := new(ExperimentalFeaturesResult)
49+
req := &internalRequest{
50+
endpoint: "/experimental-features",
51+
method: http.MethodGet,
52+
withRequest: nil,
53+
withResponse: &resp,
54+
withQueryParams: map[string]string{},
55+
acceptedStatusCodes: []int{http.StatusOK},
56+
functionName: "GetExperimentalFeatures",
57+
}
58+
59+
if err := ef.client.executeRequest(ctx, req); err != nil {
60+
return nil, err
61+
}
62+
63+
return resp, nil
64+
}
65+
66+
func (ef *ExperimentalFeatures) Update() (*ExperimentalFeaturesResult, error) {
67+
return ef.UpdateWithContext(context.Background())
68+
}
69+
70+
func (ef *ExperimentalFeatures) UpdateWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) {
71+
request := ExperimentalFeaturesBase{
72+
VectorStore: ef.VectorStore,
73+
LogsRoute: ef.LogsRoute,
74+
Metrics: ef.Metrics,
75+
EditDocumentsByFunction: ef.EditDocumentsByFunction,
76+
ContainsFilter: ef.ContainsFilter,
77+
}
78+
resp := new(ExperimentalFeaturesResult)
79+
req := &internalRequest{
80+
endpoint: "/experimental-features",
81+
method: http.MethodPatch,
82+
contentType: contentTypeJSON,
83+
withRequest: request,
84+
withResponse: resp,
85+
withQueryParams: nil,
86+
acceptedStatusCodes: []int{http.StatusOK},
87+
functionName: "UpdateExperimentalFeatures",
88+
}
89+
if err := ef.client.executeRequest(ctx, req); err != nil {
90+
return nil, err
91+
}
92+
return resp, nil
93+
}

features_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package meilisearch
2+
3+
import (
4+
"crypto/tls"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestGet_ExperimentalFeatures(t *testing.T) {
11+
sv := setup(t, "")
12+
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{
13+
InsecureSkipVerify: true,
14+
}))
15+
16+
tests := []struct {
17+
name string
18+
client ServiceManager
19+
}{
20+
{
21+
name: "TestGetStats",
22+
client: sv,
23+
},
24+
{
25+
name: "TestGetStatsWithCustomClient",
26+
client: customSv,
27+
},
28+
}
29+
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
ef := tt.client.ExperimentalFeatures()
33+
gotResp, err := ef.Get()
34+
require.NoError(t, err)
35+
require.NotNil(t, gotResp, "ExperimentalFeatures.Get() should not return nil value")
36+
})
37+
}
38+
}
39+
40+
func TestUpdate_ExperimentalFeatures(t *testing.T) {
41+
sv := setup(t, "")
42+
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{
43+
InsecureSkipVerify: true,
44+
}))
45+
46+
tests := []struct {
47+
name string
48+
client ServiceManager
49+
}{
50+
{
51+
name: "TestUpdateStats",
52+
client: sv,
53+
},
54+
{
55+
name: "TestUpdateStatsWithCustomClient",
56+
client: customSv,
57+
},
58+
}
59+
60+
for _, tt := range tests {
61+
t.Run(tt.name, func(t *testing.T) {
62+
ef := tt.client.ExperimentalFeatures()
63+
ef.SetVectorStore(true)
64+
ef.SetLogsRoute(true)
65+
ef.SetMetrics(true)
66+
ef.SetEditDocumentsByFunction(true)
67+
ef.SetContainsFilter(true)
68+
gotResp, err := ef.Update()
69+
require.NoError(t, err)
70+
require.Equal(t, true, gotResp.VectorStore, "ExperimentalFeatures.Update() should return vectorStore as true")
71+
require.Equal(t, true, gotResp.LogsRoute, "ExperimentalFeatures.Update() should return logsRoute as true")
72+
require.Equal(t, true, gotResp.Metrics, "ExperimentalFeatures.Update() should return metrics as true")
73+
require.Equal(t, true, gotResp.EditDocumentsByFunction, "ExperimentalFeatures.Update() should return editDocumentsByFunction as true")
74+
require.Equal(t, true, gotResp.ContainsFilter, "ExperimentalFeatures.Update() should return containsFilter as true")
75+
})
76+
}
77+
}

meilisearch.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package meilisearch
33
import (
44
"context"
55
"fmt"
6-
"github.com/golang-jwt/jwt/v4"
76
"net/http"
87
"strconv"
98
"time"
9+
10+
"github.com/golang-jwt/jwt/v4"
1011
)
1112

1213
type meilisearch struct {
@@ -161,6 +162,9 @@ type ServiceManager interface {
161162
// CreateSnapshotWithContext create database snapshot from meilisearch and support parent context
162163
CreateSnapshotWithContext(ctx context.Context) (*TaskInfo, error)
163164

165+
// ExperimentalFeatures returns the experimental features manager.
166+
ExperimentalFeatures() *ExperimentalFeatures
167+
164168
// Close closes the connection to the Meilisearch server.
165169
Close()
166170
}

types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,23 @@ type DocumentsResult struct {
540540
Total int64 `json:"total"`
541541
}
542542

543+
// ExperimentalFeaturesResult represents the experimental features result from the API.
544+
type ExperimentalFeaturesBase struct {
545+
VectorStore *bool `json:"vectorStore,omitempty"`
546+
LogsRoute *bool `json:"logsRoute,omitempty"`
547+
Metrics *bool `json:"metrics,omitempty"`
548+
EditDocumentsByFunction *bool `json:"editDocumentsByFunction,omitempty"`
549+
ContainsFilter *bool `json:"containsFilter,omitempty"`
550+
}
551+
552+
type ExperimentalFeaturesResult struct {
553+
VectorStore bool `json:"vectorStore"`
554+
LogsRoute bool `json:"logsRoute"`
555+
Metrics bool `json:"metrics"`
556+
EditDocumentsByFunction bool `json:"editDocumentsByFunction"`
557+
ContainsFilter bool `json:"containsFilter"`
558+
}
559+
543560
type SwapIndexesParams struct {
544561
Indexes []string `json:"indexes"`
545562
}

0 commit comments

Comments
 (0)