github.com/weaviate/weaviate@v1.24.6/entities/deepcopy/models_deepcopy.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package deepcopy
    13  
    14  import "github.com/weaviate/weaviate/entities/models"
    15  
    16  func Schema(s *models.Schema) *models.Schema {
    17  	classes := make([]*models.Class, len(s.Classes))
    18  	for i, class := range s.Classes {
    19  		classes[i] = Class(class)
    20  	}
    21  
    22  	return &models.Schema{Name: s.Name, Maintainer: s.Maintainer, Classes: classes}
    23  }
    24  
    25  func Class(c *models.Class) *models.Class {
    26  	if c == nil {
    27  		return nil
    28  	}
    29  
    30  	var properties []*models.Property = nil
    31  	if c.Properties != nil {
    32  		properties = make([]*models.Property, len(c.Properties))
    33  		for i, prop := range c.Properties {
    34  			properties[i] = Prop(prop)
    35  		}
    36  	}
    37  	var replicationConf *models.ReplicationConfig = nil
    38  	if c.ReplicationConfig != nil {
    39  		replicationConf = &models.ReplicationConfig{Factor: c.ReplicationConfig.Factor}
    40  	}
    41  
    42  	return &models.Class{
    43  		Class:               c.Class,
    44  		Description:         c.Description,
    45  		ModuleConfig:        c.ModuleConfig,
    46  		ShardingConfig:      c.ShardingConfig,
    47  		VectorIndexConfig:   c.VectorIndexConfig,
    48  		VectorIndexType:     c.VectorIndexType,
    49  		ReplicationConfig:   replicationConf,
    50  		Vectorizer:          c.Vectorizer,
    51  		InvertedIndexConfig: InvertedIndexConfig(c.InvertedIndexConfig),
    52  		Properties:          properties,
    53  	}
    54  }
    55  
    56  func Prop(p *models.Property) *models.Property {
    57  	return &models.Property{
    58  		DataType:        p.DataType,
    59  		Description:     p.Description,
    60  		ModuleConfig:    p.ModuleConfig,
    61  		Name:            p.Name,
    62  		Tokenization:    p.Tokenization,
    63  		IndexFilterable: ptrBoolCopy(p.IndexFilterable),
    64  		IndexSearchable: ptrBoolCopy(p.IndexSearchable),
    65  	}
    66  }
    67  
    68  func ptrBoolCopy(ptrBool *bool) *bool {
    69  	if ptrBool != nil {
    70  		b := *ptrBool
    71  		return &b
    72  	}
    73  	return nil
    74  }
    75  
    76  func InvertedIndexConfig(i *models.InvertedIndexConfig) *models.InvertedIndexConfig {
    77  	if i == nil {
    78  		return nil
    79  	}
    80  
    81  	var bm25 *models.BM25Config = nil
    82  	if i.Bm25 != nil {
    83  		bm25 = &models.BM25Config{B: i.Bm25.B, K1: i.Bm25.K1}
    84  	}
    85  
    86  	var stopwords *models.StopwordConfig = nil
    87  	if i.Stopwords != nil {
    88  		stopwords = &models.StopwordConfig{Additions: i.Stopwords.Additions, Preset: i.Stopwords.Preset, Removals: i.Stopwords.Removals}
    89  	}
    90  
    91  	return &models.InvertedIndexConfig{
    92  		Bm25:                   bm25,
    93  		CleanupIntervalSeconds: i.CleanupIntervalSeconds,
    94  		IndexNullState:         i.IndexNullState,
    95  		IndexPropertyLength:    i.IndexPropertyLength,
    96  		IndexTimestamps:        i.IndexTimestamps,
    97  		Stopwords:              stopwords,
    98  	}
    99  }