Skip to content

Commit 92b0f44

Browse files
authored
Add PrefixSearch and FacetSearch settings (#631)
* Add functions * Add tests * Fix tests * Add code samples * Fix types * Fix tests * Fix linter
1 parent 54296cb commit 92b0f44

File tree

6 files changed

+617
-0
lines changed

6 files changed

+617
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,15 @@ update_localized_attribute_settings_1: |-
943943
})
944944
reset_localized_attribute_settings_1: |-
945945
client.index("INDEX_NAME").ResetLocalizedAttributes()
946+
get_facet_search_settings_1: |-
947+
client.Index("books").GetFacetSearch()
948+
update_facet_search_settings_1: |-
949+
client.Index("books").UpdateFacetSearch(false)
950+
reset_facet_search_settings_1: |-
951+
client.Index("books").ResetFacetSearch()
952+
get_prefix_search_settings_1: |-
953+
client.Index("books").GetPrefixSearch()
954+
update_prefix_search_settings_1: |-
955+
client.Index("books").UpdatePrefixSearch("disabled")
956+
reset_prefix_search_settings_1: |-
957+
client.Index("books").ResetPrefixSearch()

index_interface.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,30 @@ type SettingsManager interface {
472472

473473
// ResetLocalizedAttributesWithContext reset the localized attributes settings using the provided context for cancellation
474474
ResetLocalizedAttributesWithContext(ctx context.Context) (*TaskInfo, error)
475+
476+
// UpdatePrefixSearch updates the prefix search setting of the index.
477+
UpdatePrefixSearch(request string) (*TaskInfo, error)
478+
479+
// UpdatePrefixSearchWithContext updates the prefix search setting of the index using the provided context for cancellation.
480+
UpdatePrefixSearchWithContext(ctx context.Context, request string) (*TaskInfo, error)
481+
482+
// ResetPrefixSearch resets the prefix search setting of the index to default value.
483+
ResetPrefixSearch() (*TaskInfo, error)
484+
485+
// ResetPrefixSearchWithContext resets the prefix search setting of the index to default value using the provided context for cancellation.
486+
ResetPrefixSearchWithContext(ctx context.Context) (*TaskInfo, error)
487+
488+
// UpdateFacetSearch updates the facet search setting of the index.
489+
UpdateFacetSearch(request bool) (*TaskInfo, error)
490+
491+
// UpdateFacetSearchWithContext updates the facet search setting of the index using the provided context for cancellation.
492+
UpdateFacetSearchWithContext(ctx context.Context, request bool) (*TaskInfo, error)
493+
494+
// ResetFacetSearch resets the facet search setting of the index to default value.
495+
ResetFacetSearch() (*TaskInfo, error)
496+
497+
// ResetFacetSearchWithContext resets the facet search setting of the index to default value using the provided context for cancellation.
498+
ResetFacetSearchWithContext(ctx context.Context) (*TaskInfo, error)
475499
}
476500

477501
type SettingsReader interface {
@@ -614,4 +638,16 @@ type SettingsReader interface {
614638
// GetLocalizedAttributesWithContext get the localized attributes settings of an index using the provided context for cancellation
615639
// https://www.meilisearch.com/docs/reference/api/settings#get-localized-attributes-settings
616640
GetLocalizedAttributesWithContext(ctx context.Context) ([]*LocalizedAttributes, error)
641+
642+
// GetPrefixSearch retrieves the prefix search setting of the index.
643+
GetPrefixSearch() (*string, error)
644+
645+
// GetPrefixSearchWithContext retrieves the prefix search setting of the index using the provided context for cancellation.
646+
GetPrefixSearchWithContext(ctx context.Context) (*string, error)
647+
648+
// GetFacetSearch retrieves the facet search setting of the index.
649+
GetFacetSearch() (bool, error)
650+
651+
// GetFacetSearchWithContext retrieves the facet search setting of the index using the provided context for cancellation.
652+
GetFacetSearchWithContext(ctx context.Context) (bool, error)
617653
}

index_settings.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,3 +1164,125 @@ func (i *index) ResetLocalizedAttributesWithContext(ctx context.Context) (*TaskI
11641164
}
11651165
return resp, nil
11661166
}
1167+
1168+
func (i *index) GetPrefixSearch() (*string, error) {
1169+
return i.GetPrefixSearchWithContext(context.Background())
1170+
}
1171+
1172+
func (i *index) GetPrefixSearchWithContext(ctx context.Context) (*string, error) {
1173+
resp := new(string)
1174+
req := &internalRequest{
1175+
endpoint: "/indexes/" + i.uid + "/settings/prefix-search",
1176+
method: http.MethodGet,
1177+
withRequest: nil,
1178+
withResponse: resp,
1179+
acceptedStatusCodes: []int{http.StatusOK},
1180+
functionName: "GetPrefixSearch",
1181+
}
1182+
if err := i.client.executeRequest(ctx, req); err != nil {
1183+
return nil, err
1184+
}
1185+
return resp, nil
1186+
}
1187+
1188+
func (i *index) UpdatePrefixSearch(request string) (*TaskInfo, error) {
1189+
return i.UpdatePrefixSearchWithContext(context.Background(), request)
1190+
}
1191+
1192+
func (i *index) UpdatePrefixSearchWithContext(ctx context.Context, request string) (*TaskInfo, error) {
1193+
resp := new(TaskInfo)
1194+
req := &internalRequest{
1195+
endpoint: "/indexes/" + i.uid + "/settings/prefix-search",
1196+
method: http.MethodPut,
1197+
contentType: contentTypeJSON,
1198+
withRequest: &request,
1199+
withResponse: resp,
1200+
acceptedStatusCodes: []int{http.StatusAccepted},
1201+
functionName: "UpdatePrefixSearch",
1202+
}
1203+
if err := i.client.executeRequest(ctx, req); err != nil {
1204+
return nil, err
1205+
}
1206+
return resp, nil
1207+
}
1208+
1209+
func (i *index) ResetPrefixSearch() (*TaskInfo, error) {
1210+
return i.ResetPrefixSearchWithContext(context.Background())
1211+
}
1212+
1213+
func (i *index) ResetPrefixSearchWithContext(ctx context.Context) (*TaskInfo, error) {
1214+
resp := new(TaskInfo)
1215+
req := &internalRequest{
1216+
endpoint: "/indexes/" + i.uid + "/settings/prefix-search",
1217+
method: http.MethodDelete,
1218+
withRequest: nil,
1219+
withResponse: resp,
1220+
acceptedStatusCodes: []int{http.StatusAccepted},
1221+
functionName: "ResetPrefixSearch",
1222+
}
1223+
if err := i.client.executeRequest(ctx, req); err != nil {
1224+
return nil, err
1225+
}
1226+
return resp, nil
1227+
}
1228+
1229+
func (i *index) GetFacetSearch() (bool, error) {
1230+
return i.GetFacetSearchWithContext(context.Background())
1231+
}
1232+
1233+
func (i *index) GetFacetSearchWithContext(ctx context.Context) (bool, error) {
1234+
var resp bool
1235+
req := &internalRequest{
1236+
endpoint: "/indexes/" + i.uid + "/settings/facet-search",
1237+
method: http.MethodGet,
1238+
withRequest: nil,
1239+
withResponse: &resp,
1240+
acceptedStatusCodes: []int{http.StatusOK},
1241+
functionName: "GetFacetSearch",
1242+
}
1243+
if err := i.client.executeRequest(ctx, req); err != nil {
1244+
return false, err
1245+
}
1246+
return resp, nil
1247+
}
1248+
1249+
func (i *index) UpdateFacetSearch(request bool) (*TaskInfo, error) {
1250+
return i.UpdateFacetSearchWithContext(context.Background(), request)
1251+
}
1252+
1253+
func (i *index) UpdateFacetSearchWithContext(ctx context.Context, request bool) (*TaskInfo, error) {
1254+
resp := new(TaskInfo)
1255+
req := &internalRequest{
1256+
endpoint: "/indexes/" + i.uid + "/settings/facet-search",
1257+
method: http.MethodPut,
1258+
contentType: contentTypeJSON,
1259+
withRequest: &request,
1260+
withResponse: resp,
1261+
acceptedStatusCodes: []int{http.StatusAccepted},
1262+
functionName: "UpdateFacetSearch",
1263+
}
1264+
if err := i.client.executeRequest(ctx, req); err != nil {
1265+
return nil, err
1266+
}
1267+
return resp, nil
1268+
}
1269+
1270+
func (i *index) ResetFacetSearch() (*TaskInfo, error) {
1271+
return i.ResetFacetSearchWithContext(context.Background())
1272+
}
1273+
1274+
func (i *index) ResetFacetSearchWithContext(ctx context.Context) (*TaskInfo, error) {
1275+
resp := new(TaskInfo)
1276+
req := &internalRequest{
1277+
endpoint: "/indexes/" + i.uid + "/settings/facet-search",
1278+
method: http.MethodDelete,
1279+
withRequest: nil,
1280+
withResponse: resp,
1281+
acceptedStatusCodes: []int{http.StatusAccepted},
1282+
functionName: "ResetFacetSearch",
1283+
}
1284+
if err := i.client.executeRequest(ctx, req); err != nil {
1285+
return nil, err
1286+
}
1287+
return resp, nil
1288+
}

0 commit comments

Comments
 (0)