github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/inverted_reindexer_utils.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  	"regexp"
    16  
    17  	"github.com/weaviate/weaviate/adapters/repos/db/helpers"
    18  	"github.com/weaviate/weaviate/entities/models"
    19  	"github.com/weaviate/weaviate/entities/schema"
    20  )
    21  
    22  func GetPropNameAndIndexTypeFromBucketName(bucketName string) (string, PropertyIndexType) {
    23  	propRegexpGroup := "(?P<propName>.*)"
    24  
    25  	types := []struct {
    26  		indexType    PropertyIndexType
    27  		bucketNameFn func(string) string
    28  	}{
    29  		{
    30  			IndexTypePropNull,
    31  			helpers.BucketFromPropNameNullLSM,
    32  		},
    33  		{
    34  			IndexTypePropLength,
    35  			helpers.BucketFromPropNameLengthLSM,
    36  		},
    37  		{
    38  			IndexTypePropSearchableValue,
    39  			helpers.BucketSearchableFromPropNameLSM,
    40  		},
    41  		{
    42  			IndexTypePropValue,
    43  			helpers.BucketFromPropNameLSM,
    44  		},
    45  	}
    46  
    47  	for _, t := range types {
    48  		r, err := regexp.Compile("^" + t.bucketNameFn(propRegexpGroup) + "$")
    49  		if err != nil {
    50  			continue
    51  		}
    52  		matches := r.FindStringSubmatch(bucketName)
    53  		if len(matches) > 0 {
    54  			return matches[r.SubexpIndex("propName")], t.indexType
    55  		}
    56  	}
    57  	return "", 0
    58  }
    59  
    60  type reindexablePropertyChecker struct {
    61  	reindexables map[string]map[PropertyIndexType]struct{}
    62  	props        map[string]*models.Property
    63  }
    64  
    65  func newReindexablePropertyChecker(reindexableProperties []ReindexableProperty, class *models.Class) *reindexablePropertyChecker {
    66  	reindexables := map[string]map[PropertyIndexType]struct{}{}
    67  	props := map[string]*models.Property{}
    68  	for _, property := range reindexableProperties {
    69  		if _, ok := reindexables[property.PropertyName]; !ok {
    70  			reindexables[property.PropertyName] = map[PropertyIndexType]struct{}{}
    71  		}
    72  		reindexables[property.PropertyName][property.IndexType] = struct{}{}
    73  		props[property.PropertyName], _ = schema.GetPropertyByName(class, property.PropertyName)
    74  	}
    75  	return &reindexablePropertyChecker{reindexables, props}
    76  }
    77  
    78  func (c *reindexablePropertyChecker) isReindexable(propName string, indexType PropertyIndexType) bool {
    79  	if _, ok := c.reindexables[propName]; ok {
    80  		_, ok := c.reindexables[propName][indexType]
    81  		return ok
    82  	}
    83  	return false
    84  }
    85  
    86  func (c *reindexablePropertyChecker) getSchemaProp(propName string) *models.Property {
    87  	return c.props[propName]
    88  }