(indexDef *cbgt.IndexDef)
| 210 | } |
| 211 | |
| 212 | func getSourceNamesFromIndexDef(indexDef *cbgt.IndexDef) ([]string, error) { |
| 213 | if len(indexDef.Params) > 0 { |
| 214 | bleveParamBytes := []byte(indexDef.Params) |
| 215 | docConfig, _, _, err := jsonparser.Get(bleveParamBytes, "doc_config") |
| 216 | if err != nil { |
| 217 | // couldn't find doc_config to detect the mode |
| 218 | return []string{indexDef.SourceName}, nil |
| 219 | } |
| 220 | |
| 221 | docConfigMode, _, _, _ := jsonparser.Get(docConfig, "mode") |
| 222 | if strings.HasPrefix(string(docConfigMode), ConfigModeCollPrefix) { |
| 223 | // look up the scope/collection details from the cache. |
| 224 | scopeName, collectionNames := metaFieldValCache.getScopeCollectionNames(indexDef.Name) |
| 225 | if len(scopeName) > 0 && len(collectionNames) > 0 { |
| 226 | sourceNames := make([]string, len(collectionNames)) |
| 227 | for i := range collectionNames { |
| 228 | sourceNames[i] = indexDef.SourceName + ":" + scopeName + ":" + collectionNames[i] |
| 229 | } |
| 230 | return sourceNames, nil |
| 231 | } |
| 232 | |
| 233 | // parse it again if the cache is empty like that in a unit test. |
| 234 | bmapping, _, _, err := jsonparser.Get(bleveParamBytes, "mapping") |
| 235 | if err != nil { |
| 236 | return nil, err |
| 237 | } |
| 238 | |
| 239 | mapping := bleve.NewIndexMapping() |
| 240 | err = UnmarshalJSON(bmapping, mapping) |
| 241 | if err != nil { |
| 242 | return nil, err |
| 243 | } |
| 244 | |
| 245 | sName, colNames, _, err := getScopeCollTypeMappings(mapping, true) |
| 246 | if err != nil { |
| 247 | return nil, err |
| 248 | } |
| 249 | |
| 250 | sourceNames := make([]string, len(colNames)) |
| 251 | for i, colName := range colNames { |
| 252 | sourceNames[i] = indexDef.SourceName + ":" + sName + ":" + colName |
| 253 | } |
| 254 | return sourceNames, nil |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return []string{indexDef.SourceName}, nil |
| 259 | } |
| 260 | |
| 261 | // an interface to abstract the bare minimum aspect of a cbgt.Manager |
| 262 | // that we need, so that we can stub the interface for testing |
no test coverage detected