fix bug of measurement recommend of token6 complete op and token7 hierarchy recommend

This commit is contained in:
douxu 2025-12-23 14:52:39 +08:00
parent 41e2998739
commit f45f10507b
3 changed files with 42 additions and 20 deletions

View File

@ -181,7 +181,7 @@ INSERT INTO public.bus_bus_1_stable (id, global_uuid, attribute_group, uvpw_thre
umargin_pmax, umargin_qmax, umargin_ulim, umargin_plim_percent, umargin_qlim_percent, umargin_ulim_percent
) VALUES (
1,
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
'stable',
95,
10,
@ -203,7 +203,7 @@ INSERT INTO public.bus_bus_1_model (id, global_uuid, attribute_group,
ui_percent, ui_kv, ui_pa, stability_rated_current, stability_dynamic_steady_current, load_adjustment_min, load_adjustment_max, bus_type, csc_s3_max, csc_s3_min, csc_i3_max, csc_i3_min, csc_z3s_max, csc_z3s_min, csc_s1_max, csc_s1_min, csc_i1_max, csc_i1_min, csc_z1s_max, csc_z1s_min, csc_base_voltage, csc_base_capacity
) VALUES (
1,
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
'model',
100,
35,
@ -233,7 +233,7 @@ INSERT INTO public.bus_bus_1_base_extend (id, global_uuid, attribute_group,
bus_num, unom_kv
) VALUES (
1,
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
'base_extend',
1,
NULL

View File

@ -233,16 +233,13 @@ func insertAllHierarchySuggestions(ac *redisearch.Autocompleter) error {
compTagStr := fmt.Sprintf("comptag%d_%d_%d_%d_%d", S, Y, Z, D, I)
fullCompTagPath := fmt.Sprintf("%s.%s", gridZoneStationNSPath, compTagStr)
suggestions = append(suggestions, redisearch.Suggestion{Term: fullCompTagPath, Score: defaultScore})
for _, metric := range configMetrics {
fullMetricPath := fmt.Sprintf("%s.%s", fullCompTagPath, metric)
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMetricPath, Score: defaultScore})
// J: measTag Index (1-3)
for J := 1; J <= 3; J++ {
measTagStr := fmt.Sprintf("comptag%d_%d_%d_%d_%d_%d", S, Y, Z, D, I, J)
fullMeasurementPath := fmt.Sprintf("%s.%s", fullMetricPath, measTagStr)
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMeasurementPath, Score: defaultScore})
}
fullConfigPath := fmt.Sprintf("%s.%s", fullCompTagPath, "bay")
suggestions = append(suggestions, redisearch.Suggestion{Term: fullConfigPath, Score: defaultScore})
// J: measTag Index (1-3)
for J := 1; J <= 3; J++ {
measTagStr := fmt.Sprintf("meas%d_%d_%d_%d_%d_%d", S, Y, Z, D, I, J)
fullMeasurementPath := fmt.Sprintf("%s.%s", fullCompTagPath, measTagStr)
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMeasurementPath, Score: defaultScore})
}
}
}

View File

@ -6,11 +6,12 @@ import (
"errors"
"fmt"
"math"
"strings"
"modelRT/constants"
"modelRT/diagram"
"modelRT/logger"
"modelRT/util"
"strings"
"github.com/RediSearch/redisearch-go/v2/redisearch"
redigo "github.com/gomodule/redigo/redis"
@ -469,17 +470,34 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
// runFuzzySearch define func to process redis fuzzy search
func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string, hierarchy constants.RecommendHierarchyType) ([]string, error) {
var configToken string
var comparePrefix string
searchInputLen := len(searchInput)
compareHierarchyLen := int(hierarchy)
comparePrefix = searchPrefix
if hierarchy == constants.MeasTagRecommendHierarchyType {
fmt.Printf("run fuzzy search, original searchPrefix:%s\n", searchPrefix)
compareHierarchyLen = int(hierarchy) - 1
lastDotIndex := strings.LastIndex(searchPrefix, ".")
if lastDotIndex == -1 {
configToken = ""
} else {
configToken = searchPrefix[lastDotIndex+1:]
comparePrefix = searchPrefix[:lastDotIndex]
}
}
for searchInputLen != 0 {
fuzzyInput := strings.Join([]string{comparePrefix, searchInput}, ".")
results, err := ac.SuggestOpts(searchInput, redisearch.SuggestOptions{
results, err := ac.SuggestOpts(fuzzyInput, redisearch.SuggestOptions{
Num: math.MaxInt16,
Fuzzy: true,
WithScores: false,
WithPayloads: false,
})
if err != nil {
logger.Error(ctx, "query key by redis fuzzy search failed", "query_key", searchInput, "error", err)
logger.Error(ctx, "query key by redis fuzzy search failed", "query_key", fuzzyInput, "error", err)
return nil, fmt.Errorf("redisearch suggest failed: %w", err)
}
@ -494,24 +512,31 @@ func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string
var recommends []string
for _, result := range results {
term := result.Term
var termSliceLen int
var termHierarchyLen int
var termPrefix string
var termLastPart string
lastDotIndex := strings.LastIndex(term, ".")
if lastDotIndex == -1 {
termPrefix = ""
termLastPart = term
} else {
termPrefix = term[:lastDotIndex]
termLastPart = term[lastDotIndex+1:]
}
if result.Term == "" {
termSliceLen = 1
termHierarchyLen = 1
} else {
termSliceLen = strings.Count(result.Term, ".") + 1
termHierarchyLen = strings.Count(result.Term, ".") + 1
}
if termSliceLen == int(hierarchy) && termPrefix == searchPrefix {
recommends = append(recommends, result.Term)
if termHierarchyLen == compareHierarchyLen && termPrefix == comparePrefix && strings.HasPrefix(termLastPart, searchInput) {
recommend := result.Term
if hierarchy == constants.MeasTagRecommendHierarchyType {
recommend = strings.Join([]string{termPrefix, configToken, termLastPart}, ".")
}
recommends = append(recommends, recommend)
}
}
return recommends, nil