github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/shard_write_inverted.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 db 13 14 import ( 15 "fmt" 16 17 "github.com/weaviate/weaviate/adapters/repos/db/inverted" 18 "github.com/weaviate/weaviate/entities/filters" 19 "github.com/weaviate/weaviate/entities/schema" 20 "github.com/weaviate/weaviate/entities/storobj" 21 ) 22 23 func isPropertyForLength(dt schema.DataType) bool { 24 switch dt { 25 case schema.DataTypeInt, schema.DataTypeNumber, schema.DataTypeBoolean, schema.DataTypeDate: 26 return false 27 default: 28 return true 29 } 30 } 31 32 func (s *Shard) AnalyzeObject(object *storobj.Object) ([]inverted.Property, []inverted.NilProperty, error) { 33 schemaModel := s.index.getSchema.GetSchemaSkipAuth().Objects 34 c, err := schema.GetClassByName(schemaModel, object.Class().String()) 35 if err != nil { 36 return nil, nil, err 37 } 38 39 var schemaMap map[string]interface{} 40 41 if object.Properties() == nil { 42 schemaMap = make(map[string]interface{}) 43 } else { 44 maybeSchemaMap, ok := object.Properties().(map[string]interface{}) 45 if !ok { 46 return nil, nil, fmt.Errorf("expected schema to be map, but got %T", object.Properties()) 47 } 48 schemaMap = maybeSchemaMap 49 } 50 51 // add nil for all properties that are not part of the object so that they can be added to the inverted index for 52 // the null state (if enabled) 53 var nilProps []inverted.NilProperty 54 if s.index.invertedIndexConfig.IndexNullState { 55 for _, prop := range c.Properties { 56 dt := schema.DataType(prop.DataType[0]) 57 // some datatypes are not added to the inverted index, so we can skip them here 58 if dt == schema.DataTypeGeoCoordinates || dt == schema.DataTypePhoneNumber || dt == schema.DataTypeBlob { 59 continue 60 } 61 62 // Add props as nil props if 63 // 1. They are not in the schema map ( == nil) 64 // 2. Their inverted index is enabled 65 _, ok := schemaMap[prop.Name] 66 if !ok && inverted.HasInvertedIndex(prop) { 67 nilProps = append(nilProps, inverted.NilProperty{ 68 Name: prop.Name, 69 AddToPropertyLength: isPropertyForLength(dt), 70 }) 71 } 72 } 73 } 74 75 if s.index.invertedIndexConfig.IndexTimestamps { 76 if schemaMap == nil { 77 schemaMap = make(map[string]interface{}) 78 } 79 schemaMap[filters.InternalPropCreationTimeUnix] = object.Object.CreationTimeUnix 80 schemaMap[filters.InternalPropLastUpdateTimeUnix] = object.Object.LastUpdateTimeUnix 81 } 82 83 props, err := inverted.NewAnalyzer(s.isFallbackToSearchable).Object(schemaMap, c.Properties, object.ID()) 84 return props, nilProps, err 85 }