92 lines
2.7 KiB
Go
92 lines
2.7 KiB
Go
// Package model define model struct of model runtime service
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"modelRT/constants"
|
|
"modelRT/diagram"
|
|
|
|
"github.com/RediSearch/redisearch-go/v2/redisearch"
|
|
)
|
|
|
|
// StoreComponentColumnRecommend binds token6 component config to component table column names.
|
|
func StoreComponentColumnRecommend(ctx context.Context, compTagToFullPath map[string]string, isLocalCompTagToFullPath map[string]string, componentColumnNames []string) error {
|
|
rdb := diagram.GetRedisClientInstance()
|
|
pipe := rdb.Pipeline()
|
|
|
|
pipe.SAdd(ctx, constants.RedisAllConfigSetKey, constants.ComponentConfigKey)
|
|
|
|
if len(componentColumnNames) == 0 {
|
|
_, err := pipe.Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
componentColumnMembers := stringSliceToAny(componentColumnNames)
|
|
pipe.SAdd(ctx, constants.RedisAllMeasTagSetKey, componentColumnMembers...)
|
|
|
|
sug := make([]redisearch.Suggestion, 0, len(compTagToFullPath)*len(componentColumnNames)*4)
|
|
for compTag, fullPath := range compTagToFullPath {
|
|
specCompMeasKey := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, compTag)
|
|
pipe.SAdd(ctx, specCompMeasKey, componentColumnMembers...)
|
|
pipe.HSet(ctx, componentColumnGroupKey(compTag), componentColumnHashFields(componentColumnNames)...)
|
|
|
|
isLocalFullPath := isLocalCompTagToFullPath[compTag]
|
|
fullConfigTerm := fmt.Sprintf("%s.%s", fullPath, constants.ComponentConfigKey)
|
|
sug = append(sug, redisearch.Suggestion{
|
|
Term: fullConfigTerm,
|
|
Score: constants.DefaultScore,
|
|
})
|
|
|
|
if isLocalFullPath != "" {
|
|
localConfigTerm := fmt.Sprintf("%s.%s", isLocalFullPath, constants.ComponentConfigKey)
|
|
sug = append(sug, redisearch.Suggestion{
|
|
Term: localConfigTerm,
|
|
Score: constants.DefaultScore,
|
|
})
|
|
}
|
|
|
|
for _, columnName := range componentColumnNames {
|
|
fullColumnTerm := fmt.Sprintf("%s.%s.%s", fullPath, constants.ComponentConfigKey, columnName)
|
|
sug = append(sug, redisearch.Suggestion{
|
|
Term: fullColumnTerm,
|
|
Score: constants.DefaultScore,
|
|
})
|
|
|
|
if isLocalFullPath == "" {
|
|
continue
|
|
}
|
|
|
|
localColumnTerm := fmt.Sprintf("%s.%s.%s", isLocalFullPath, constants.ComponentConfigKey, columnName)
|
|
sug = append(sug, redisearch.Suggestion{
|
|
Term: localColumnTerm,
|
|
Score: constants.DefaultScore,
|
|
})
|
|
}
|
|
}
|
|
|
|
if len(sug) > 0 {
|
|
ac.AddTerms(sug...)
|
|
}
|
|
|
|
_, err := pipe.Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func stringSliceToAny(values []string) []any {
|
|
members := make([]any, 0, len(values))
|
|
for _, value := range values {
|
|
members = append(members, value)
|
|
}
|
|
return members
|
|
}
|
|
|
|
func componentColumnGroupKey(compTag string) string {
|
|
return recommendGroupKey(compTag, constants.ComponentConfigKey)
|
|
}
|
|
|
|
func componentColumnHashFields(columnNames []string) []any {
|
|
return recommendHashFields(columnNames)
|
|
}
|