@@ -24,7 +24,17 @@ func NewAccount() *Account {
2424// which belong to different Algolia applications. To perform the same operation
2525// on indices which belong to the same Algolia application, use Client.CopyIndex
2626// which is optimized for this use-case.
27- func (a * Account ) CopyIndex (src , dst * Index , opts ... interface {}) (* wait.Group , error ) {
27+ func (a * Account ) CopyIndex (src , dst * Index , opts ... string ) (* wait.Group , error ) {
28+ // Validate scope option
29+ hasScope := len (opts ) > 0
30+ if hasScope {
31+ for _ , scope := range opts {
32+ if scope != "rules" && scope != "synonyms" && scope != "settings" {
33+ return nil , fmt .Errorf ("wrong scope: should be 'rules', 'synonyms'or 'settings'" )
34+ }
35+ }
36+ }
37+
2838 if src .GetAppID () == dst .GetAppID () {
2939 return nil , errs .ErrSameAppID
3040 }
@@ -36,7 +46,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
3646 g := wait .NewGroup ()
3747
3848 // Copy synonyms
39- {
49+ if ! hasScope || SliceContains ( opts , "synonyms" ) {
4050 it , err := src .BrowseSynonyms ()
4151 if err != nil {
4252 return nil , fmt .Errorf ("cannot browse source index synonyms: %v" , err )
@@ -66,7 +76,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
6676 }
6777
6878 // Copy rules
69- {
79+ if ! hasScope || SliceContains ( opts , "rules" ) {
7080 it , err := src .BrowseRules ()
7181 if err != nil {
7282 return nil , fmt .Errorf ("cannot browse source index rules: %v" , err )
@@ -95,7 +105,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
95105 }
96106
97107 // Copy settings
98- {
108+ if ! hasScope || SliceContains ( opts , "settings" ) {
99109 settings , err := src .GetSettings ()
100110 if err != nil {
101111 return nil , fmt .Errorf ("cannot retrieve source index settings: %v" , err )
@@ -141,7 +151,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
141151 }
142152
143153 // Send the last batch
144- res , err := dst .SaveObjects (objects , opts )
154+ res , err := dst .SaveObjects (objects )
145155 if err != nil {
146156 return nil , fmt .Errorf ("error while saving batch of objects: %v" , err )
147157 }
0 commit comments