MCPcopy Create free account
hub / github.com/couchbase/cbft / PrepareIndexDef

Function PrepareIndexDef

pindex_bleve.go:497–612  ·  view source on GitHub ↗
(mgr *cbgt.Manager, indexDef *cbgt.IndexDef)

Source from the content-addressed store, hash-verified

495}
496
497func PrepareIndexDef(mgr *cbgt.Manager, indexDef *cbgt.IndexDef) (
498 *cbgt.IndexDef, error) {
499 if indexDef == nil {
500 return nil, fmt.Errorf("bleve: Prepare, indexDef is nil")
501 }
502
503 if CurrentNodeDefsFetcher == nil {
504 return limitIndexDef(indexDef)
505 }
506
507 nodeDefs, err := CurrentNodeDefsFetcher.Get()
508 if err != nil {
509 return nil, fmt.Errorf("bleve: Prepare, nodeDefs unavailable: err: %v", err)
510 }
511
512 var collectionsSupported bool
513 if versionTracker != nil &&
514 versionTracker.clusterCompatibleForVersion(FeatureCollectionVersion) {
515 collectionsSupported =
516 cbgt.IsFeatureSupportedByCluster(FeatureCollections, nodeDefs)
517 }
518
519 if collectionsSupported {
520 // Use "gocbcore" for DCP streaming if cluster is 7.0+
521 indexDef.SourceType = cbgt.SOURCE_GOCBCORE
522 }
523
524 bp := NewBleveParams()
525 if len(indexDef.Params) > 0 {
526 b, err := bleveMappingUI.CleanseJSON([]byte(indexDef.Params))
527 if err != nil {
528 return nil, fmt.Errorf("bleve: Prepare, CleanseJSON,"+
529 " err: %v", err)
530 }
531
532 err = json.Unmarshal(b, bp)
533 if err != nil {
534 if typeErr, ok := err.(*json.UnmarshalTypeError); ok {
535 if typeErr.Type.String() == "map[string]json.RawMessage" {
536 return nil, fmt.Errorf("bleve: Prepare,"+
537 " JSON parse was expecting a string key/field-name"+
538 " but instead saw a %s", typeErr.Value)
539 }
540 }
541 return nil, fmt.Errorf("bleve: Prepare, err: %v", err)
542 }
543
544 if indexType, ok := bp.Store["indexType"].(string); ok {
545 if indexType == "scorch" {
546 // If indexType were "scorch", the "kvStoreName" setting isn't
547 // really applicable, so drop the setting.
548 delete(bp.Store, "kvStoreName")
549 }
550 }
551
552 // figure out the scope/collection details from mappings
553 // and perform the validation checks.
554 if strings.HasPrefix(bp.DocConfig.Mode, ConfigModeCollPrefix) {

Callers

nothing calls this directly

Calls 9

limitIndexDefFunction · 0.85
NewBleveParamsFunction · 0.85
checkSourceCompatabilityFunction · 0.85
GetMethod · 0.80
UnmarshalMethod · 0.80
MarshalMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected