----------------------------------------------------------------------------- API to retrieve the scope & unique list of collection names from the provided index definition.
(indexDef *cbgt.IndexDef)
| 295 | // API to retrieve the scope & unique list of collection names from the |
| 296 | // provided index definition. |
| 297 | func GetScopeCollectionsFromIndexDef(indexDef *cbgt.IndexDef) ( |
| 298 | scope string, collections []string, err error) { |
| 299 | if indexDef == nil { |
| 300 | return "", nil, fmt.Errorf("no index-def provided") |
| 301 | } |
| 302 | |
| 303 | bp := NewBleveParams() |
| 304 | if len(indexDef.Params) > 0 { |
| 305 | if err = json.Unmarshal([]byte(indexDef.Params), bp); err != nil { |
| 306 | return "", nil, err |
| 307 | } |
| 308 | |
| 309 | if strings.HasPrefix(bp.DocConfig.Mode, ConfigModeCollPrefix) { |
| 310 | if im, ok := bp.Mapping.(*mapping.IndexMappingImpl); ok { |
| 311 | var collectionNames []string |
| 312 | scope, collectionNames, _, err := getScopeCollTypeMappings(im, false) |
| 313 | if err != nil { |
| 314 | return "", nil, err |
| 315 | } |
| 316 | |
| 317 | uniqueCollections := map[string]struct{}{} |
| 318 | for _, coll := range collectionNames { |
| 319 | if _, exists := uniqueCollections[coll]; !exists { |
| 320 | uniqueCollections[coll] = struct{}{} |
| 321 | collections = append(collections, coll) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return scope, collections, nil |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return "_default", []string{"_default"}, nil |
| 331 | } |
| 332 | |
| 333 | func multiCollection(colls []Collection) bool { |
| 334 | hash := make(map[string]struct{}, 1) |
no test coverage detected