fix bug of measurement recommend of token6 complete op and token7 hierarchy recommend
This commit is contained in:
parent
41e2998739
commit
f45f10507b
|
|
@ -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
|
umargin_pmax, umargin_qmax, umargin_ulim, umargin_plim_percent, umargin_qlim_percent, umargin_ulim_percent
|
||||||
) VALUES (
|
) VALUES (
|
||||||
1,
|
1,
|
||||||
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
|
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
|
||||||
'stable',
|
'stable',
|
||||||
95,
|
95,
|
||||||
10,
|
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
|
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 (
|
) VALUES (
|
||||||
1,
|
1,
|
||||||
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
|
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
|
||||||
'model',
|
'model',
|
||||||
100,
|
100,
|
||||||
35,
|
35,
|
||||||
|
|
@ -233,7 +233,7 @@ INSERT INTO public.bus_bus_1_base_extend (id, global_uuid, attribute_group,
|
||||||
bus_num, unom_kv
|
bus_num, unom_kv
|
||||||
) VALUES (
|
) VALUES (
|
||||||
1,
|
1,
|
||||||
'ba5d7240-a25b-4f6a-a0fd-412638fa4d33',
|
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
|
||||||
'base_extend',
|
'base_extend',
|
||||||
1,
|
1,
|
||||||
NULL
|
NULL
|
||||||
|
|
|
||||||
|
|
@ -233,16 +233,13 @@ func insertAllHierarchySuggestions(ac *redisearch.Autocompleter) error {
|
||||||
compTagStr := fmt.Sprintf("comptag%d_%d_%d_%d_%d", S, Y, Z, D, I)
|
compTagStr := fmt.Sprintf("comptag%d_%d_%d_%d_%d", S, Y, Z, D, I)
|
||||||
fullCompTagPath := fmt.Sprintf("%s.%s", gridZoneStationNSPath, compTagStr)
|
fullCompTagPath := fmt.Sprintf("%s.%s", gridZoneStationNSPath, compTagStr)
|
||||||
suggestions = append(suggestions, redisearch.Suggestion{Term: fullCompTagPath, Score: defaultScore})
|
suggestions = append(suggestions, redisearch.Suggestion{Term: fullCompTagPath, Score: defaultScore})
|
||||||
|
fullConfigPath := fmt.Sprintf("%s.%s", fullCompTagPath, "bay")
|
||||||
for _, metric := range configMetrics {
|
suggestions = append(suggestions, redisearch.Suggestion{Term: fullConfigPath, Score: defaultScore})
|
||||||
fullMetricPath := fmt.Sprintf("%s.%s", fullCompTagPath, metric)
|
// J: measTag Index (1-3)
|
||||||
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMetricPath, Score: defaultScore})
|
for J := 1; J <= 3; J++ {
|
||||||
// J: measTag Index (1-3)
|
measTagStr := fmt.Sprintf("meas%d_%d_%d_%d_%d_%d", S, Y, Z, D, I, J)
|
||||||
for J := 1; J <= 3; J++ {
|
fullMeasurementPath := fmt.Sprintf("%s.%s", fullCompTagPath, measTagStr)
|
||||||
measTagStr := fmt.Sprintf("comptag%d_%d_%d_%d_%d_%d", S, Y, Z, D, I, J)
|
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMeasurementPath, Score: defaultScore})
|
||||||
fullMeasurementPath := fmt.Sprintf("%s.%s", fullMetricPath, measTagStr)
|
|
||||||
suggestions = append(suggestions, redisearch.Suggestion{Term: fullMeasurementPath, Score: defaultScore})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"modelRT/constants"
|
"modelRT/constants"
|
||||||
"modelRT/diagram"
|
"modelRT/diagram"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/util"
|
"modelRT/util"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/RediSearch/redisearch-go/v2/redisearch"
|
"github.com/RediSearch/redisearch-go/v2/redisearch"
|
||||||
redigo "github.com/gomodule/redigo/redis"
|
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
|
// runFuzzySearch define func to process redis fuzzy search
|
||||||
func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string, hierarchy constants.RecommendHierarchyType) ([]string, error) {
|
func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string, hierarchy constants.RecommendHierarchyType) ([]string, error) {
|
||||||
|
var configToken string
|
||||||
|
var comparePrefix string
|
||||||
searchInputLen := len(searchInput)
|
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 {
|
for searchInputLen != 0 {
|
||||||
|
fuzzyInput := strings.Join([]string{comparePrefix, searchInput}, ".")
|
||||||
results, err := ac.SuggestOpts(searchInput, redisearch.SuggestOptions{
|
results, err := ac.SuggestOpts(searchInput, redisearch.SuggestOptions{
|
||||||
|
results, err := ac.SuggestOpts(fuzzyInput, redisearch.SuggestOptions{
|
||||||
Num: math.MaxInt16,
|
Num: math.MaxInt16,
|
||||||
Fuzzy: true,
|
Fuzzy: true,
|
||||||
WithScores: false,
|
WithScores: false,
|
||||||
WithPayloads: false,
|
WithPayloads: false,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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)
|
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
|
var recommends []string
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
term := result.Term
|
term := result.Term
|
||||||
var termSliceLen int
|
var termHierarchyLen int
|
||||||
var termPrefix string
|
var termPrefix string
|
||||||
|
var termLastPart string
|
||||||
|
|
||||||
lastDotIndex := strings.LastIndex(term, ".")
|
lastDotIndex := strings.LastIndex(term, ".")
|
||||||
if lastDotIndex == -1 {
|
if lastDotIndex == -1 {
|
||||||
termPrefix = ""
|
termPrefix = ""
|
||||||
|
termLastPart = term
|
||||||
} else {
|
} else {
|
||||||
termPrefix = term[:lastDotIndex]
|
termPrefix = term[:lastDotIndex]
|
||||||
|
termLastPart = term[lastDotIndex+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Term == "" {
|
if result.Term == "" {
|
||||||
termSliceLen = 1
|
termHierarchyLen = 1
|
||||||
} else {
|
} else {
|
||||||
termSliceLen = strings.Count(result.Term, ".") + 1
|
termHierarchyLen = strings.Count(result.Term, ".") + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if termSliceLen == int(hierarchy) && termPrefix == searchPrefix {
|
if termHierarchyLen == compareHierarchyLen && termPrefix == comparePrefix && strings.HasPrefix(termLastPart, searchInput) {
|
||||||
recommends = append(recommends, result.Term)
|
recommend := result.Term
|
||||||
|
if hierarchy == constants.MeasTagRecommendHierarchyType {
|
||||||
|
recommend = strings.Join([]string{termPrefix, configToken, termLastPart}, ".")
|
||||||
|
}
|
||||||
|
recommends = append(recommends, recommend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return recommends, nil
|
return recommends, nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue