add fullpath completion of component attribute group recommend
This commit is contained in:
parent
42751c1020
commit
8e4bdfd0e9
|
|
@ -89,6 +89,8 @@ func GetFullMeasurementSet(db *gorm.DB) (*orm.MeasurementSet, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mSet.AllConfigTags = append(mSet.AllConfigTags, "bay")
|
||||||
|
|
||||||
var measurements []struct {
|
var measurements []struct {
|
||||||
orm.Measurement
|
orm.Measurement
|
||||||
CompTag string `gorm:"column:comp_tag"`
|
CompTag string `gorm:"column:comp_tag"`
|
||||||
|
|
|
||||||
6
main.go
6
main.go
|
|
@ -157,19 +157,21 @@ func main() {
|
||||||
logger.Error(ctx, "generate component measurement group failed", "error", err)
|
logger.Error(ctx, "generate component measurement group failed", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = model.TraverseMeasurementGroupTables(ctx, *measurementSet)
|
parentPath, err := model.TraverseMeasurementGroupTables(ctx, *measurementSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "store component measurement group into redis failed", "error", err)
|
logger.Error(ctx, "store component measurement group into redis failed", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("generate full path mapping result:%v\n", parentPath)
|
||||||
|
|
||||||
compAttrSet, err := database.GenAllAttributeMap(tx)
|
compAttrSet, err := database.GenAllAttributeMap(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "generate component attribute group failed", "error", err)
|
logger.Error(ctx, "generate component attribute group failed", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = model.TraverseAttributeGroupTables(ctx, tx, compAttrSet)
|
err = model.TraverseAttributeGroupTables(ctx, tx, parentPath, compAttrSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "store component attribute group into redis failed", "error", err)
|
logger.Error(ctx, "store component attribute group into redis failed", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/orm"
|
"modelRT/orm"
|
||||||
|
|
||||||
|
"github.com/RediSearch/redisearch-go/v2/redisearch"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -20,7 +22,7 @@ type columnParam struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseAttributeGroupTables define func to traverse component attribute group tables
|
// TraverseAttributeGroupTables define func to traverse component attribute group tables
|
||||||
func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compAttrSet map[string]orm.AttributeSet) error {
|
func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compTagToFullPath map[string]string, compAttrSet map[string]orm.AttributeSet) error {
|
||||||
var tableNames []string
|
var tableNames []string
|
||||||
|
|
||||||
result := db.Model(&orm.ProjectManager{}).Pluck("name", &tableNames)
|
result := db.Model(&orm.ProjectManager{}).Pluck("name", &tableNames)
|
||||||
|
|
@ -92,17 +94,23 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compAttrSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fullPath := compTagToFullPath[attrSet.CompTag]
|
||||||
|
if fullPath == "" {
|
||||||
|
err := errors.New("can not find full parent path from mapping by component tag")
|
||||||
|
logger.Error(ctx, "find full parent path by from mapping by component tag failed", "component_tag", attrSet.CompTag, "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
columnParam := columnParam{
|
columnParam := columnParam{
|
||||||
AttributeType: attributeType,
|
AttributeType: attributeType,
|
||||||
AttributeGroup: attributeGroup,
|
AttributeGroup: attributeGroup,
|
||||||
}
|
}
|
||||||
go storeAttributeGroup(ctx, attrSet, columnParam)
|
go storeAttributeGroup(ctx, attrSet, fullPath, columnParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, colParams columnParam) {
|
func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, fullPath string, colParams columnParam) {
|
||||||
rdb := diagram.GetRedisClientInstance()
|
rdb := diagram.GetRedisClientInstance()
|
||||||
pipe := rdb.Pipeline()
|
pipe := rdb.Pipeline()
|
||||||
|
|
||||||
|
|
@ -114,9 +122,17 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, col
|
||||||
attrNameMembers := make([]string, 0, len(colParams.AttributeGroup))
|
attrNameMembers := make([]string, 0, len(colParams.AttributeGroup))
|
||||||
attrbutesGroups := make([]any, 0, len(colParams.AttributeGroup)*2)
|
attrbutesGroups := make([]any, 0, len(colParams.AttributeGroup)*2)
|
||||||
attributeGroupKey := fmt.Sprintf("%s_%s", attributeSet.CompTag, colParams.AttributeType)
|
attributeGroupKey := fmt.Sprintf("%s_%s", attributeSet.CompTag, colParams.AttributeType)
|
||||||
|
|
||||||
|
sug := make([]redisearch.Suggestion, 0, len(colParams.AttributeGroup))
|
||||||
for attrName, attrValue := range colParams.AttributeGroup {
|
for attrName, attrValue := range colParams.AttributeGroup {
|
||||||
attrbutesGroups = append(attrbutesGroups, attrName, attrValue)
|
attrbutesGroups = append(attrbutesGroups, attrName, attrValue)
|
||||||
attrNameMembers = append(attrNameMembers, attrName)
|
attrNameMembers = append(attrNameMembers, attrName)
|
||||||
|
|
||||||
|
term := fmt.Sprintf("%s.%s", fullPath, attrName)
|
||||||
|
sug = append(sug, redisearch.Suggestion{
|
||||||
|
Term: term,
|
||||||
|
Score: constants.DefaultScore,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(attrbutesGroups) > 0 {
|
if len(attrbutesGroups) > 0 {
|
||||||
|
|
@ -127,7 +143,10 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, col
|
||||||
pipe.SAdd(ctx, specCompMeasKey, attrNameMembers)
|
pipe.SAdd(ctx, specCompMeasKey, attrNameMembers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 增加 suggestion 索引内容
|
if len(sug) > 0 {
|
||||||
|
ac.AddTerms(sug...)
|
||||||
|
}
|
||||||
|
|
||||||
_, err := pipe.Exec(ctx)
|
_, err := pipe.Exec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "init component attribute group recommend content failed", "error", err)
|
logger.Error(ctx, "init component attribute group recommend content failed", "error", err)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"modelRT/constants"
|
"modelRT/constants"
|
||||||
|
|
@ -15,10 +16,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TraverseMeasurementGroupTables define func to traverse component measurement group tables
|
// TraverseMeasurementGroupTables define func to traverse component measurement group tables
|
||||||
func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.MeasurementSet) error {
|
func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.MeasurementSet) (map[string]string, error) {
|
||||||
rdb := diagram.GetRedisClientInstance()
|
rdb := diagram.GetRedisClientInstance()
|
||||||
pipe := rdb.Pipeline()
|
pipe := rdb.Pipeline()
|
||||||
|
|
||||||
|
compTagToFullPath := make(map[string]string)
|
||||||
|
|
||||||
zoneToGridPath := make(map[string]string)
|
zoneToGridPath := make(map[string]string)
|
||||||
for gridTag, zoneTags := range measSet.GridToZoneTags {
|
for gridTag, zoneTags := range measSet.GridToZoneTags {
|
||||||
for _, zoneTag := range zoneTags {
|
for _, zoneTag := range zoneTags {
|
||||||
|
|
@ -68,7 +71,7 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
safeSAdd(constants.RedisAllStationSetKey, measSet.AllStationTags)
|
safeSAdd(constants.RedisAllStationSetKey, measSet.AllStationTags)
|
||||||
safeSAdd(constants.RedisAllCompNSPathSetKey, measSet.AllCompNSPaths)
|
safeSAdd(constants.RedisAllCompNSPathSetKey, measSet.AllCompNSPaths)
|
||||||
safeSAdd(constants.RedisAllCompTagSetKey, measSet.AllCompTags)
|
safeSAdd(constants.RedisAllCompTagSetKey, measSet.AllCompTags)
|
||||||
safeSAdd(constants.RedisAllConfigSetKey, []string{"bay"})
|
safeSAdd(constants.RedisAllConfigSetKey, measSet.AllConfigTags)
|
||||||
safeSAdd(constants.RedisAllMeasTagSetKey, measSet.AllMeasTags)
|
safeSAdd(constants.RedisAllMeasTagSetKey, measSet.AllMeasTags)
|
||||||
|
|
||||||
// building the grid -> zones hierarchy
|
// building the grid -> zones hierarchy
|
||||||
|
|
@ -89,7 +92,7 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
if !exists {
|
if !exists {
|
||||||
err := fmt.Errorf("zone tag to grid tag mapping not found for zoneTag: %s", zoneTag)
|
err := fmt.Errorf("zone tag to grid tag mapping not found for zoneTag: %s", zoneTag)
|
||||||
logger.Error(ctx, "zone tag to grid tag mapping not found", "zoneTag", zoneTag, "error", err)
|
logger.Error(ctx, "zone tag to grid tag mapping not found", "zoneTag", zoneTag, "error", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, stationTag := range stationTags {
|
for _, stationTag := range stationTags {
|
||||||
|
|
@ -108,7 +111,7 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
if !exists {
|
if !exists {
|
||||||
err := fmt.Errorf("station tag to zone tag mapping not found for stationTag: %s", stationTag)
|
err := fmt.Errorf("station tag to zone tag mapping not found for stationTag: %s", stationTag)
|
||||||
logger.Error(ctx, "zone tag to grid tag mapping not found", "stationTag", stationTag, "error", err)
|
logger.Error(ctx, "zone tag to grid tag mapping not found", "stationTag", stationTag, "error", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, nsPath := range compNSPaths {
|
for _, nsPath := range compNSPaths {
|
||||||
|
|
@ -126,11 +129,14 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
if !exists {
|
if !exists {
|
||||||
err := fmt.Errorf("component nspath tag to station tag mapping not found for compNSPath: %s", compNSPath)
|
err := fmt.Errorf("component nspath tag to station tag mapping not found for compNSPath: %s", compNSPath)
|
||||||
logger.Error(ctx, "component nspath tag to station tag mapping not found", "compNSPath", compNSPath, "error", err)
|
logger.Error(ctx, "component nspath tag to station tag mapping not found", "compNSPath", compNSPath, "error", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, compTag := range compTags {
|
for _, compTag := range compTags {
|
||||||
term := fmt.Sprintf("%s.%s.%s", parentPath, compNSPath, compTag)
|
fullPath := fmt.Sprintf("%s.%s.%s", parentPath, compNSPath, compTag)
|
||||||
|
compTagToFullPath[compTag] = fullPath
|
||||||
|
|
||||||
|
term := fullPath
|
||||||
sug = append(sug, redisearch.Suggestion{Term: term, Score: constants.DefaultScore})
|
sug = append(sug, redisearch.Suggestion{Term: term, Score: constants.DefaultScore})
|
||||||
}
|
}
|
||||||
safeSAdd(fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, compNSPath), compTags)
|
safeSAdd(fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, compNSPath), compTags)
|
||||||
|
|
@ -144,7 +150,7 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
if !exists {
|
if !exists {
|
||||||
err := fmt.Errorf("component tag to component nspath mapping not found for compTag: %s", compTag)
|
err := fmt.Errorf("component tag to component nspath mapping not found for compTag: %s", compTag)
|
||||||
logger.Error(ctx, "component tag to component nspath mapping not found", "compTag", compTag, "error", err)
|
logger.Error(ctx, "component tag to component nspath mapping not found", "compTag", compTag, "error", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, measTag := range measTags {
|
for _, measTag := range measTags {
|
||||||
|
|
@ -155,10 +161,11 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
ac.AddTerms(sug...)
|
ac.AddTerms(sug...)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmders, err := pipe.Exec(ctx)
|
var allErrs []error
|
||||||
if err != nil {
|
cmders, execErr := pipe.Exec(ctx)
|
||||||
logger.Error(ctx, "pipeline execution failed", "error", err)
|
if execErr != nil {
|
||||||
return err
|
logger.Error(ctx, "pipeline execution failed", "error", execErr)
|
||||||
|
allErrs = append(allErrs, execErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for errors in each subcommand of the pipeline
|
// check for errors in each subcommand of the pipeline
|
||||||
|
|
@ -169,9 +176,14 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
||||||
"command", cmder.Name(),
|
"command", cmder.Name(),
|
||||||
"args", cmder.Args(),
|
"args", cmder.Args(),
|
||||||
"error", cmdErr)
|
"error", cmdErr)
|
||||||
|
allErrs = append(allErrs, cmdErr)
|
||||||
}
|
}
|
||||||
return cmdErr
|
}
|
||||||
|
if len(allErrs) > 0 {
|
||||||
|
return nil, errors.Join(allErrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return compTagToFullPath, nil
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type MeasurementSet struct {
|
||||||
AllStationTags []string
|
AllStationTags []string
|
||||||
AllCompNSPaths []string
|
AllCompNSPaths []string
|
||||||
AllCompTags []string
|
AllCompTags []string
|
||||||
|
AllConfigTags []string
|
||||||
AllMeasTags []string
|
AllMeasTags []string
|
||||||
|
|
||||||
GridToZoneTags map[string][]string // Key: GridTag, Value: ZoneTags
|
GridToZoneTags map[string][]string // Key: GridTag, Value: ZoneTags
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue