fix bug of t4-t7 model combine prefix string func
This commit is contained in:
parent
9499e579b3
commit
c16680d4c2
|
|
@ -88,3 +88,12 @@ func (r RecommendHierarchyType) String() string {
|
|||
return "unknown_recommend_type(" + string(rune(r)) + ")"
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
// FullRecommendLength define full recommend length with all tokens
|
||||
FullRecommendLength = "t1.t2.t3.t4.t5.t6.t7"
|
||||
// IsLocalRecommendLength define is local recommend length with specific tokens
|
||||
IsLocalRecommendLength = "t4.t5.t6.t7"
|
||||
// token1.token2.token3.token4.token7
|
||||
// token4.token7
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@ 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"
|
||||
|
|
@ -160,9 +159,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 2:
|
||||
// zone tagname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ZoneRecommendHierarchyType, constants.RedisAllZoneSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ZoneRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllZoneSetKey, inputSlice, fanInChan)
|
||||
// component tagname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompTagRecommendHierarchyType, constants.RedisAllCompTagSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompTagRecommendHierarchyType, constants.IsLocalRecommendLength, constants.RedisAllCompTagSetKey, inputSlice, fanInChan)
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
result := <-fanInChan
|
||||
|
|
@ -176,9 +175,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 3:
|
||||
// station tanname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.StationRecommendHierarchyType, constants.RedisAllStationSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.StationRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllStationSetKey, inputSlice, fanInChan)
|
||||
// config search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ConfigRecommendHierarchyType, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ConfigRecommendHierarchyType, constants.IsLocalRecommendLength, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
|
|
@ -193,9 +192,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 4:
|
||||
// component nspath search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompNSPathRecommendHierarchyType, constants.RedisAllCompNSPathSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompNSPathRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllCompNSPathSetKey, inputSlice, fanInChan)
|
||||
// measurement tagname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.MeasTagRecommendHierarchyType, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.MeasTagRecommendHierarchyType, constants.IsLocalRecommendLength, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
|
|
@ -210,10 +209,10 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 5:
|
||||
// component tagname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompTagRecommendHierarchyType, constants.RedisAllCompTagSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.CompTagRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllCompTagSetKey, inputSlice, fanInChan)
|
||||
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
for range 1 {
|
||||
result := <-fanInChan
|
||||
if result.Err != nil {
|
||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
||||
|
|
@ -225,10 +224,10 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 6:
|
||||
// config search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ConfigRecommendHierarchyType, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.ConfigRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllConfigSetKey, inputSlice, fanInChan)
|
||||
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
for range 1 {
|
||||
result := <-fanInChan
|
||||
if result.Err != nil {
|
||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
||||
|
|
@ -240,10 +239,10 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
return results
|
||||
case 7:
|
||||
// measurement tagname search
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.MeasTagRecommendHierarchyType, constants.RedisAllMeasTagSetKey, inputSlice, fanInChan)
|
||||
go handleLevelFuzzySearch(ctx, rdb, constants.MeasTagRecommendHierarchyType, constants.FullRecommendLength, constants.RedisAllMeasTagSetKey, inputSlice, fanInChan)
|
||||
|
||||
results := make(map[string]SearchResult)
|
||||
for range 2 {
|
||||
for range 1 {
|
||||
result := <-fanInChan
|
||||
if result.Err != nil {
|
||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
||||
|
|
@ -312,25 +311,38 @@ func getAllKeyByNSPathLevel(ctx context.Context, rdb *redis.Client, fanInChan ch
|
|||
}
|
||||
}
|
||||
|
||||
func combineQueryResultByInput(hierarchy constants.RecommendHierarchyType, inputSlice []string, queryResults []string) []string {
|
||||
func combineQueryResultByInput(hierarchy constants.RecommendHierarchyType, recommendLenType string, inputSlice []string, queryResults []string) []string {
|
||||
prefixs := make([]string, 0, len(inputSlice))
|
||||
recommandResults := make([]string, 0, len(queryResults))
|
||||
switch hierarchy {
|
||||
// TODO 优化 case 为常量
|
||||
case 2:
|
||||
prefixs = []string{inputSlice[0]}
|
||||
case 3:
|
||||
prefixs = inputSlice[0:2]
|
||||
case 4:
|
||||
prefixs = inputSlice[0:3]
|
||||
case 5:
|
||||
prefixs = inputSlice[0:4]
|
||||
case 6:
|
||||
prefixs = inputSlice[0:5]
|
||||
case 7:
|
||||
prefixs = inputSlice[0:6]
|
||||
default:
|
||||
return []string{}
|
||||
switch recommendLenType {
|
||||
case constants.FullRecommendLength:
|
||||
switch hierarchy {
|
||||
case constants.ZoneRecommendHierarchyType:
|
||||
prefixs = []string{inputSlice[0]}
|
||||
case constants.StationRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:2]
|
||||
case constants.CompNSPathRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:3]
|
||||
case constants.CompTagRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:4]
|
||||
case constants.ConfigRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:5]
|
||||
case constants.MeasTagRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:6]
|
||||
default:
|
||||
return []string{}
|
||||
}
|
||||
case constants.IsLocalRecommendLength:
|
||||
switch hierarchy {
|
||||
case constants.CompTagRecommendHierarchyType:
|
||||
prefixs = []string{inputSlice[0]}
|
||||
case constants.ConfigRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:2]
|
||||
case constants.MeasTagRecommendHierarchyType:
|
||||
prefixs = inputSlice[0:3]
|
||||
default:
|
||||
return []string{}
|
||||
}
|
||||
}
|
||||
|
||||
for _, queryResult := range queryResults {
|
||||
|
|
@ -366,7 +378,7 @@ func getSpecificKeyByLength(hierarchy constants.RecommendHierarchyType, keyPrefi
|
|||
}
|
||||
|
||||
// handleLevelFuzzySearch define func to process recommendation logic for specific levels(level >= 2)
|
||||
func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy constants.RecommendHierarchyType, redisSetKey string, inputSlice []string, fanInChan chan SearchResult) {
|
||||
func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy constants.RecommendHierarchyType, recommendLenType string, redisSetKey string, inputSlice []string, fanInChan chan SearchResult) {
|
||||
inputSliceLen := len(inputSlice)
|
||||
searchInputIndex := inputSliceLen - 1
|
||||
searchInput := inputSlice[searchInputIndex]
|
||||
|
|
@ -391,7 +403,7 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
|||
return
|
||||
}
|
||||
|
||||
recommandResults := combineQueryResultByInput(hierarchy, inputSlice, members)
|
||||
recommandResults := combineQueryResultByInput(hierarchy, recommendLenType, inputSlice, members)
|
||||
fanInChan <- SearchResult{
|
||||
RecommendType: hierarchy,
|
||||
QueryDatas: recommandResults,
|
||||
|
|
@ -444,7 +456,7 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
|||
}
|
||||
|
||||
if len(recommends) == 0 {
|
||||
logger.Error(ctx, "fuzzy search without result", "hierarchy", hierarchy, "search_input", searchInput, "error", err)
|
||||
logger.Info(ctx, "fuzzy search without result", "hierarchy", hierarchy, "search_input", searchInput, "error", err)
|
||||
}
|
||||
|
||||
fanInChan <- SearchResult{
|
||||
|
|
|
|||
Loading…
Reference in New Issue