Repository: algolia/algoliasearch-client-go
Pull request #628 (2020-10-15 08:37:17)

feat: add re-ranking parameters to search parameters and settings
| Q                 | A
| ----------------- | ----------
| Bug fix?          | no
| New feature?      | yes
| Need Doc update   | yes

## Describe your change

Add the enableReRanking and reRankingApplyFilter fields to search parameters and settings.




Patch:
diff --git a/algolia/internal/gen/options.go b/algolia/internal/gen/options.go
index 88d53bb7..696d6c68 100644
--- a/algolia/internal/gen/options.go
+++ b/algolia/internal/gen/options.go
@@ -117,6 +117,8 @@ var options = []Option{
 	{"enablePersonalization", Search|Settings, false, ""},
 	{"personalizationImpact", Search, 100, ""},
 	{"userToken", Search, "", ""},
+	{"enableReRanking", Search | Settings, true, ""},
+	{"reRankingApplyFilter", Search | Settings, "", ""},
 
 	// Performance
 	{"numericAttributesForFiltering", Settings, []string{}, "numericAttributesToIndex"},
diff --git a/algolia/internal/opt/enable_re_ranking.go b/algolia/internal/opt/enable_re_ranking.go
new file mode 100644
index 00000000..16adc031
--- /dev/null
+++ b/algolia/internal/opt/enable_re_ranking.go
@@ -0,0 +1,18 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import (
+	"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
+)
+
+// ExtractEnableReRanking returns the first found EnableReRankingOption from the
+// given variadic arguments or nil otherwise.
+func ExtractEnableReRanking(opts ...interface{}) *opt.EnableReRankingOption {
+	for _, o := range opts {
+		if v, ok := o.(*opt.EnableReRankingOption); ok {
+			return v
+		}
+	}
+	return nil
+}
diff --git a/algolia/internal/opt/re_ranking_apply_filter.go b/algolia/internal/opt/re_ranking_apply_filter.go
new file mode 100644
index 00000000..775b9919
--- /dev/null
+++ b/algolia/internal/opt/re_ranking_apply_filter.go
@@ -0,0 +1,18 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import (
+	"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
+)
+
+// ExtractReRankingApplyFilter returns the first found ReRankingApplyFilterOption from the
+// given variadic arguments or nil otherwise.
+func ExtractReRankingApplyFilter(opts ...interface{}) *opt.ReRankingApplyFilterOption {
+	for _, o := range opts {
+		if v, ok := o.(*opt.ReRankingApplyFilterOption); ok {
+			return v
+		}
+	}
+	return nil
+}
diff --git a/algolia/opt/enable_re_ranking.go b/algolia/opt/enable_re_ranking.go
new file mode 100644
index 00000000..ff214ef2
--- /dev/null
+++ b/algolia/opt/enable_re_ranking.go
@@ -0,0 +1,60 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import "encoding/json"
+
+// EnableReRankingOption is a wrapper for an EnableReRanking option parameter. It holds
+// the actual value of the option that can be accessed by calling Get.
+type EnableReRankingOption struct {
+	value bool
+}
+
+// EnableReRanking wraps the given value into a EnableReRankingOption.
+func EnableReRanking(v bool) *EnableReRankingOption {
+	return &EnableReRankingOption{v}
+}
+
+// Get retrieves the actual value of the option parameter.
+func (o *EnableReRankingOption) Get() bool {
+	if o == nil {
+		return true
+	}
+	return o.value
+}
+
+// MarshalJSON implements the json.Marshaler interface for
+// EnableReRankingOption.
+func (o EnableReRankingOption) MarshalJSON() ([]byte, error) {
+	return json.Marshal(o.value)
+}
+
+// UnmarshalJSON implements the json.Unmarshaler interface for
+// EnableReRankingOption.
+func (o *EnableReRankingOption) UnmarshalJSON(data []byte) error {
+	if string(data) == "null" {
+		o.value = true
+		return nil
+	}
+	return json.Unmarshal(data, &o.value)
+}
+
+// Equal returns true if the given option is equal to the instance one. In case
+// the given option is nil, we checked the instance one is set to the default
+// value of the option.
+func (o *EnableReRankingOption) Equal(o2 *EnableReRankingOption) bool {
+	if o == nil {
+		return o2 == nil || o2.value == true
+	}
+	if o2 == nil {
+		return o == nil || o.value == true
+	}
+	return o.value == o2.value
+}
+
+// EnableReRankingEqual returns true if the two options are equal.
+// In case of one option being nil, the value of the other must be nil as well
+// or be set to the default value of this option.
+func EnableReRankingEqual(o1, o2 *EnableReRankingOption) bool {
+	return o1.Equal(o2)
+}
diff --git a/algolia/opt/re_ranking_apply_filter.go b/algolia/opt/re_ranking_apply_filter.go
new file mode 100644
index 00000000..a1e43186
--- /dev/null
+++ b/algolia/opt/re_ranking_apply_filter.go
@@ -0,0 +1,60 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import "encoding/json"
+
+// ReRankingApplyFilterOption is a wrapper for an ReRankingApplyFilter option parameter. It holds
+// the actual value of the option that can be accessed by calling Get.
+type ReRankingApplyFilterOption struct {
+	value string
+}
+
+// ReRankingApplyFilter wraps the given value into a ReRankingApplyFilterOption.
+func ReRankingApplyFilter(v string) *ReRankingApplyFilterOption {
+	return &ReRankingApplyFilterOption{v}
+}
+
+// Get retrieves the actual value of the option parameter.
+func (o *ReRankingApplyFilterOption) Get() string {
+	if o == nil {
+		return ""
+	}
+	return o.value
+}
+
+// MarshalJSON implements the json.Marshaler interface for
+// ReRankingApplyFilterOption.
+func (o ReRankingApplyFilterOption) MarshalJSON() ([]byte, error) {
+	return json.Marshal(o.value)
+}
+
+// UnmarshalJSON implements the json.Unmarshaler interface for
+// ReRankingApplyFilterOption.
+func (o *ReRankingApplyFilterOption) UnmarshalJSON(data []byte) error {
+	if string(data) == "null" {
+		o.value = ""
+		return nil
+	}
+	return json.Unmarshal(data, &o.value)
+}
+
+// Equal returns true if the given option is equal to the instance one. In case
+// the given option is nil, we checked the instance one is set to the default
+// value of the option.
+func (o *ReRankingApplyFilterOption) Equal(o2 *ReRankingApplyFilterOption) bool {
+	if o == nil {
+		return o2 == nil || o2.value == ""
+	}
+	if o2 == nil {
+		return o == nil || o.value == ""
+	}
+	return o.value == o2.value
+}
+
+// ReRankingApplyFilterEqual returns true if the two options are equal.
+// In case of one option being nil, the value of the other must be nil as well
+// or be set to the default value of this option.
+func ReRankingApplyFilterEqual(o1, o2 *ReRankingApplyFilterOption) bool {
+	return o1.Equal(o2)
+}
diff --git a/algolia/search/query_params.go b/algolia/search/query_params.go
index 892a2873..e3493bf4 100644
--- a/algolia/search/query_params.go
+++ b/algolia/search/query_params.go
@@ -62,6 +62,8 @@ type QueryParams struct {
 	EnablePersonalization                   *opt.EnablePersonalizationOption                   `json:"enablePersonalization,omitempty"`
 	PersonalizationImpact                   *opt.PersonalizationImpactOption                   `json:"personalizationImpact,omitempty"`
 	UserToken                               *opt.UserTokenOption                               `json:"userToken,omitempty"`
+	EnableReRanking                         *opt.EnableReRankingOption                         `json:"enableReRanking,omitempty"`
+	ReRankingApplyFilter                    *opt.ReRankingApplyFilterOption                    `json:"reRankingApplyFilter,omitempty"`
 	Distinct                                *opt.DistinctOption                                `json:"distinct,omitempty"`
 	GetRankingInfo                          *opt.GetRankingInfoOption                          `json:"getRankingInfo,omitempty"`
 	ClickAnalytics                          *opt.ClickAnalyticsOption                          `json:"clickAnalytics,omitempty"`
@@ -132,6 +134,8 @@ func newQueryParams(opts ...interface{}) QueryParams {
 		EnablePersonalization:                   iopt.ExtractEnablePersonalization(opts...),
 		PersonalizationImpact:                   iopt.ExtractPersonalizationImpact(opts...),
 		UserToken:                               iopt.ExtractUserToken(opts...),
+		EnableReRanking:                         iopt.ExtractEnableReRanking(opts...),
+		ReRankingApplyFilter:                    iopt.ExtractReRankingApplyFilter(opts...),
 		Distinct:                                iopt.ExtractDistinct(opts...),
 		GetRankingInfo:                          iopt.ExtractGetRankingInfo(opts...),
 		ClickAnalytics:                          iopt.ExtractClickAnalytics(opts...),
@@ -316,6 +320,12 @@ func (p *QueryParams) Equal(p2 *QueryParams) bool {
 	if !p.UserToken.Equal(p2.UserToken) {
 		return false
 	}
+	if !p.EnableReRanking.Equal(p2.EnableReRanking) {
+		return false
+	}
+	if !p.ReRankingApplyFilter.Equal(p2.ReRankingApplyFilter) {
+		return false
+	}
 	if !p.Distinct.Equal(p2.Distinct) {
 		return false
 	}
diff --git a/algolia/search/settings.go b/algolia/search/settings.go
index d210680e..43bcba22 100644
--- a/algolia/search/settings.go
+++ b/algolia/search/settings.go
@@ -57,6 +57,8 @@ type Settings struct {
 	AdvancedSyntaxFeatures                  *opt.AdvancedSyntaxFeaturesOption                  `json:"advancedSyntaxFeatures,omitempty"`
 	EnableRules                             *opt.EnableRulesOption                             `json:"enableRules,omitempty"`
 	EnablePersonalization                   *opt.EnablePersonalizationOption                   `json:"enablePersonalization,omitempty"`
+	EnableReRanking                         *opt.EnableReRankingOption                         `json:"enableReRanking,omitempty"`
+	ReRankingApplyFilter                    *opt.ReRankingApplyFilterOption                    `json:"reRankingApplyFilter,omitempty"`
 	NumericAttributesForFiltering           *opt.NumericAttributesForFilteringOption           `json:"numericAttributesForFiltering,omitempty"`
 	AllowCompressionOfIntegerArray          *opt.AllowCompressionOfIntegerArrayOption          `json:"allowCompressionOfIntegerArray,omitempty"`
 	AttributeForDistinct                    *opt.AttributeForDistinctOption                    `json:"attributeForDistinct,omitempty"`
@@ -154,6 +156,8 @@ func (s *Settings) UnmarshalJSON(data []byte) error {
 		"advancedSyntaxFeatures",
 		"enableRules",
 		"enablePersonalization",
+		"enableReRanking",
+		"reRankingApplyFilter",
 		"numericAttributesForFiltering",
 		"numericAttributesToIndex",
 		"allowCompressionOfIntegerArray",
@@ -372,6 +376,14 @@ func (s Settings) Equal(s2 Settings) bool {
 		debug.Printf("Settings.EnablePersonalization are not equal: %#v != %#v\n", s.EnablePersonalization, s2.EnablePersonalization)
 		return false
 	}
+	if !opt.EnableReRankingEqual(s.EnableReRanking, s2.EnableReRanking) {
+		debug.Printf("Settings.EnableReRanking are not equal: %#v != %#v\n", s.EnableReRanking, s2.EnableReRanking)
+		return false
+	}
+	if !opt.ReRankingApplyFilterEqual(s.ReRankingApplyFilter, s2.ReRankingApplyFilter) {
+		debug.Printf("Settings.ReRankingApplyFilter are not equal: %#v != %#v\n", s.ReRankingApplyFilter, s2.ReRankingApplyFilter)
+		return false
+	}
 	if !opt.NumericAttributesForFilteringEqual(s.NumericAttributesForFiltering, s2.NumericAttributesForFiltering) {
 		debug.Printf("Settings.NumericAttributesForFiltering are not equal: %#v != %#v\n", s.NumericAttributesForFiltering, s2.NumericAttributesForFiltering)
 		return false
@@ -465,6 +477,8 @@ func (s Settings) String() string {
 	settingsStr += fmt.Sprintf("\tAdvancedSyntaxFeatures: %v,\n", stringifyReturnValues(s.AdvancedSyntaxFeatures.Get()))
 	settingsStr += fmt.Sprintf("\tEnableRules: %v,\n", stringifyReturnValues(s.EnableRules.Get()))
 	settingsStr += fmt.Sprintf("\tEnablePersonalization: %v,\n", stringifyReturnValues(s.EnablePersonalization.Get()))
+	settingsStr += fmt.Sprintf("\tEnableReRanking: %v,\n", stringifyReturnValues(s.EnableReRanking.Get()))
+	settingsStr += fmt.Sprintf("\tReRankingApplyFilter: %v,\n", stringifyReturnValues(s.ReRankingApplyFilter.Get()))
 	settingsStr += fmt.Sprintf("\tNumericAttributesForFiltering: %v,\n", stringifyReturnValues(s.NumericAttributesForFiltering.Get()))
 	settingsStr += fmt.Sprintf("\tAllowCompressionOfIntegerArray: %v,\n", stringifyReturnValues(s.AllowCompressionOfIntegerArray.Get()))
 	settingsStr += fmt.Sprintf("\tAttributeForDistinct: %v,\n", stringifyReturnValues(s.AttributeForDistinct.Get()))


Test patch:
diff --git a/algolia/internal/opt/enable_re_ranking_test.go b/algolia/internal/opt/enable_re_ranking_test.go
new file mode 100644
index 00000000..26b29d1d
--- /dev/null
+++ b/algolia/internal/opt/enable_re_ranking_test.go
@@ -0,0 +1,41 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
+	"github.com/stretchr/testify/require"
+)
+
+func TestEnableReRanking(t *testing.T) {
+	for _, c := range []struct {
+		opts     []interface{}
+		expected *opt.EnableReRankingOption
+	}{
+		{
+			opts:     []interface{}{nil},
+			expected: opt.EnableReRanking(true),
+		},
+		{
+			opts:     []interface{}{opt.EnableReRanking(true)},
+			expected: opt.EnableReRanking(true),
+		},
+		{
+			opts:     []interface{}{opt.EnableReRanking(false)},
+			expected: opt.EnableReRanking(false),
+		},
+	} {
+		var (
+			in  = ExtractEnableReRanking(c.opts...)
+			out opt.EnableReRankingOption
+		)
+		data, err := json.Marshal(&in)
+		require.NoError(t, err)
+		err = json.Unmarshal(data, &out)
+		require.NoError(t, err)
+		require.Equal(t, *c.expected, out)
+	}
+}
diff --git a/algolia/internal/opt/re_ranking_apply_filter_test.go b/algolia/internal/opt/re_ranking_apply_filter_test.go
new file mode 100644
index 00000000..c0f128dd
--- /dev/null
+++ b/algolia/internal/opt/re_ranking_apply_filter_test.go
@@ -0,0 +1,41 @@
+// Code generated by go generate. DO NOT EDIT.
+
+package opt
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
+	"github.com/stretchr/testify/require"
+)
+
+func TestReRankingApplyFilter(t *testing.T) {
+	for _, c := range []struct {
+		opts     []interface{}
+		expected *opt.ReRankingApplyFilterOption
+	}{
+		{
+			opts:     []interface{}{nil},
+			expected: opt.ReRankingApplyFilter(""),
+		},
+		{
+			opts:     []interface{}{opt.ReRankingApplyFilter("")},
+			expected: opt.ReRankingApplyFilter(""),
+		},
+		{
+			opts:     []interface{}{opt.ReRankingApplyFilter("content of the string value")},
+			expected: opt.ReRankingApplyFilter("content of the string value"),
+		},
+	} {
+		var (
+			in  = ExtractReRankingApplyFilter(c.opts...)
+			out opt.ReRankingApplyFilterOption
+		)
+		data, err := json.Marshal(&in)
+		require.NoError(t, err)
+		err = json.Unmarshal(data, &out)
+		require.NoError(t, err)
+		require.Equal(t, *c.expected, out)
+	}
+}
diff --git a/algolia/opt/option_getters_test.go b/algolia/opt/option_getters_test.go
index c807f950..34f81890 100644
--- a/algolia/opt/option_getters_test.go
+++ b/algolia/opt/option_getters_test.go
@@ -215,6 +215,12 @@ func TestOptionGetters(t *testing.T) {
 	var userToken *UserTokenOption = nil
 	userToken.Get()
 
+	var enableReRanking *EnableReRankingOption = nil
+	enableReRanking.Get()
+
+	var reRankingApplyFilter *ReRankingApplyFilterOption = nil
+	reRankingApplyFilter.Get()
+
 	var numericAttributesForFiltering *NumericAttributesForFilteringOption = nil
 	numericAttributesForFiltering.Get()