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)) + ")"
|
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"
|
"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"
|
||||||
|
|
@ -160,9 +159,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
||||||
return results
|
return results
|
||||||
case 2:
|
case 2:
|
||||||
// zone tagname search
|
// 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
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 2 {
|
||||||
result := <-fanInChan
|
result := <-fanInChan
|
||||||
|
|
@ -176,9 +175,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
||||||
return results
|
return results
|
||||||
case 3:
|
case 3:
|
||||||
// station tanname search
|
// 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
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 2 {
|
||||||
|
|
@ -193,9 +192,9 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
||||||
return results
|
return results
|
||||||
case 4:
|
case 4:
|
||||||
// component nspath search
|
// 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
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 2 {
|
||||||
|
|
@ -210,10 +209,10 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
||||||
return results
|
return results
|
||||||
case 5:
|
case 5:
|
||||||
// component tagname search
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 1 {
|
||||||
result := <-fanInChan
|
result := <-fanInChan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
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
|
return results
|
||||||
case 6:
|
case 6:
|
||||||
// config search
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 1 {
|
||||||
result := <-fanInChan
|
result := <-fanInChan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
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
|
return results
|
||||||
case 7:
|
case 7:
|
||||||
// measurement tagname search
|
// 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)
|
results := make(map[string]SearchResult)
|
||||||
for range 2 {
|
for range 1 {
|
||||||
result := <-fanInChan
|
result := <-fanInChan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
logger.Error(ctx, "query all keys at the special level from redis failed", "query_key", result.RecommendType, "error", result.Err)
|
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))
|
prefixs := make([]string, 0, len(inputSlice))
|
||||||
recommandResults := make([]string, 0, len(queryResults))
|
recommandResults := make([]string, 0, len(queryResults))
|
||||||
switch hierarchy {
|
switch recommendLenType {
|
||||||
// TODO 优化 case 为常量
|
case constants.FullRecommendLength:
|
||||||
case 2:
|
switch hierarchy {
|
||||||
prefixs = []string{inputSlice[0]}
|
case constants.ZoneRecommendHierarchyType:
|
||||||
case 3:
|
prefixs = []string{inputSlice[0]}
|
||||||
prefixs = inputSlice[0:2]
|
case constants.StationRecommendHierarchyType:
|
||||||
case 4:
|
prefixs = inputSlice[0:2]
|
||||||
prefixs = inputSlice[0:3]
|
case constants.CompNSPathRecommendHierarchyType:
|
||||||
case 5:
|
prefixs = inputSlice[0:3]
|
||||||
prefixs = inputSlice[0:4]
|
case constants.CompTagRecommendHierarchyType:
|
||||||
case 6:
|
prefixs = inputSlice[0:4]
|
||||||
prefixs = inputSlice[0:5]
|
case constants.ConfigRecommendHierarchyType:
|
||||||
case 7:
|
prefixs = inputSlice[0:5]
|
||||||
prefixs = inputSlice[0:6]
|
case constants.MeasTagRecommendHierarchyType:
|
||||||
default:
|
prefixs = inputSlice[0:6]
|
||||||
return []string{}
|
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 {
|
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)
|
// 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)
|
inputSliceLen := len(inputSlice)
|
||||||
searchInputIndex := inputSliceLen - 1
|
searchInputIndex := inputSliceLen - 1
|
||||||
searchInput := inputSlice[searchInputIndex]
|
searchInput := inputSlice[searchInputIndex]
|
||||||
|
|
@ -391,7 +403,7 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
recommandResults := combineQueryResultByInput(hierarchy, inputSlice, members)
|
recommandResults := combineQueryResultByInput(hierarchy, recommendLenType, inputSlice, members)
|
||||||
fanInChan <- SearchResult{
|
fanInChan <- SearchResult{
|
||||||
RecommendType: hierarchy,
|
RecommendType: hierarchy,
|
||||||
QueryDatas: recommandResults,
|
QueryDatas: recommandResults,
|
||||||
|
|
@ -444,7 +456,7 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(recommends) == 0 {
|
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{
|
fanInChan <- SearchResult{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue