fix bug of token6 all search result return case
This commit is contained in:
parent
7969861746
commit
941d521328
|
|
@ -24,7 +24,10 @@ type columnParam struct {
|
|||
func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compTagToFullPath map[string]string, compAttrSet map[string]orm.AttributeSet) error {
|
||||
var tableNames []string
|
||||
|
||||
result := db.Model(&orm.ProjectManager{}).Pluck("name", &tableNames)
|
||||
excludedTables := []string{"component", ""}
|
||||
result := db.Model(&orm.ProjectManager{}).
|
||||
Where("name NOT IN ?", excludedTables).
|
||||
Pluck("name", &tableNames)
|
||||
if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
|
||||
logger.Error(ctx, "query name column data from postgres table failed", "err", result.Error)
|
||||
return result.Error
|
||||
|
|
@ -36,11 +39,6 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compTagToFul
|
|||
}
|
||||
|
||||
for _, tableName := range tableNames {
|
||||
// TODO 将 tableName == "component" 进行优化
|
||||
if (tableName == "") || (tableName == "component") {
|
||||
continue
|
||||
}
|
||||
|
||||
var records []map[string]any
|
||||
err := db.Table(tableName).Find(&records).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
|
|
@ -127,9 +125,15 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, ful
|
|||
attrbutesGroups = append(attrbutesGroups, attrName, attrValue)
|
||||
attrNameMembers = append(attrNameMembers, attrName)
|
||||
|
||||
term := fmt.Sprintf("%s.%s", fullPath, attrName)
|
||||
configTerm := fmt.Sprintf("%s.%s", fullPath, colParams.AttributeType)
|
||||
sug = append(sug, redisearch.Suggestion{
|
||||
Term: term,
|
||||
Term: configTerm,
|
||||
Score: constants.DefaultScore,
|
||||
})
|
||||
|
||||
measTerm := fmt.Sprintf("%s.%s.%s", fullPath, colParams.AttributeType, attrName)
|
||||
sug = append(sug, redisearch.Suggestion{
|
||||
Term: measTerm,
|
||||
Score: constants.DefaultScore,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,8 +153,11 @@ func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.Measurement
|
|||
}
|
||||
|
||||
for _, measTag := range measTags {
|
||||
term := fmt.Sprintf("%s.%s.%s", parentPath, compTag, measTag)
|
||||
sug = append(sug, redisearch.Suggestion{Term: term, Score: constants.DefaultScore})
|
||||
configTerm := fmt.Sprintf("%s.%s.%s", parentPath, compTag, "bay")
|
||||
sug = append(sug, redisearch.Suggestion{Term: configTerm, Score: constants.DefaultScore})
|
||||
|
||||
measTerm := fmt.Sprintf("%s.%s.%s.%s", parentPath, compTag, "bay", measTag)
|
||||
sug = append(sug, redisearch.Suggestion{Term: measTerm, Score: constants.DefaultScore})
|
||||
}
|
||||
safeSAdd(fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, compTag), measTags)
|
||||
ac.AddTerms(sug...)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ func CleanupRecommendRedisCache(ctx context.Context) error {
|
|||
|
||||
for _, attrType := range attrTypes {
|
||||
pattern := fmt.Sprintf("*_%s", attrType)
|
||||
fmt.Printf("delete patterm:%s\n", pattern)
|
||||
if err := deleteKeysByPattern(ctx, rdb, pattern); err != nil {
|
||||
logger.Warn(ctx, "cleanup attribute type pattern failed",
|
||||
"attr_type", attrType, "pattern", pattern, "error", err)
|
||||
|
|
@ -45,6 +44,7 @@ func CleanupRecommendRedisCache(ctx context.Context) error {
|
|||
|
||||
if err := rdb.Del(ctx, fixedKeys...).Err(); err != nil {
|
||||
logger.Error(ctx, "delete fixed redis keys failed", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
patterns := []string{
|
||||
|
|
@ -58,6 +58,7 @@ func CleanupRecommendRedisCache(ctx context.Context) error {
|
|||
for _, pattern := range patterns {
|
||||
if err := deleteKeysByPattern(ctx, rdb, pattern); err != nil {
|
||||
logger.Warn(ctx, "cleanup pattern keys failed", "pattern", pattern, "error", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -434,6 +434,29 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
|||
}
|
||||
|
||||
recommandResults := combineQueryResultByInput(hierarchy, recommendLenType, inputSlice, members)
|
||||
if hierarchy == constants.ConfigRecommendHierarchyType || hierarchy == constants.MeasTagRecommendHierarchyType {
|
||||
// check the relevance between the config hierarchy and measurement hierarchy output and the request input, i.e., use FT.SUGGET search_suggestions_dict "recommandResult" max 1 for an exact query to check if the result exists
|
||||
secondConfirmResults := make([]string, 0, len(recommandResults))
|
||||
for _, res := range recommandResults {
|
||||
results, err := ac.SuggestOpts(res, redisearch.SuggestOptions{
|
||||
Num: 1,
|
||||
Fuzzy: false,
|
||||
WithScores: false,
|
||||
WithPayloads: false,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error(ctx, "config hierarchy query key second confirmation failed", "query_key", res, "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
continue
|
||||
}
|
||||
secondConfirmResults = append(secondConfirmResults, res)
|
||||
}
|
||||
|
||||
recommandResults = secondConfirmResults
|
||||
}
|
||||
fanInChan <- SearchResult{
|
||||
RecommendType: hierarchy,
|
||||
QueryDatas: recommandResults,
|
||||
|
|
@ -485,10 +508,6 @@ func handleLevelFuzzySearch(ctx context.Context, rdb *redis.Client, hierarchy co
|
|||
return
|
||||
}
|
||||
|
||||
if hierarchy == constants.MeasTagRecommendHierarchyType || hierarchy == constants.ConfigRecommendHierarchyType {
|
||||
fmt.Printf("fuzzy origin recommneds:%v\n", recommends)
|
||||
}
|
||||
|
||||
if len(recommends) == 0 {
|
||||
logger.Info(ctx, "fuzzy search without result", "hierarchy", hierarchy, "search_input", searchInput, "error", err)
|
||||
}
|
||||
|
|
@ -510,7 +529,6 @@ func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string
|
|||
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 {
|
||||
|
|
@ -519,8 +537,6 @@ func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string
|
|||
configToken = searchPrefix[lastDotIndex+1:]
|
||||
comparePrefix = searchPrefix[:lastDotIndex]
|
||||
}
|
||||
fmt.Printf("run fuzzy search, original searchPrefix:%s\n", searchPrefix)
|
||||
fmt.Printf("run fuzzy search, original comparePrefix:%s\n", comparePrefix)
|
||||
}
|
||||
|
||||
for searchInputLen != 0 {
|
||||
|
|
@ -543,8 +559,6 @@ func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string
|
|||
searchInputLen = len(searchInput)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("len of fuzzy search results:%d\n", len(results))
|
||||
fmt.Printf("fuzzy search results:%v\n", results)
|
||||
|
||||
var recommends []string
|
||||
for _, result := range results {
|
||||
|
|
@ -568,23 +582,15 @@ func runFuzzySearch(ctx context.Context, searchInput string, searchPrefix string
|
|||
termHierarchyLen = strings.Count(result.Term, ".") + 1
|
||||
}
|
||||
|
||||
fmt.Printf("termHierarchyLen:%d\n", termHierarchyLen)
|
||||
fmt.Printf("compareHierarchy:%d\n", compareHierarchyLen)
|
||||
fmt.Printf("termPrefix:%s\n", termPrefix)
|
||||
fmt.Printf("comparePrefix:%s\n", comparePrefix)
|
||||
if termHierarchyLen == compareHierarchyLen && termPrefix == comparePrefix && strings.HasPrefix(termLastPart, searchInput) {
|
||||
recommend := result.Term
|
||||
if hierarchy == constants.MeasTagRecommendHierarchyType {
|
||||
recommend = strings.Join([]string{termPrefix, configToken, termLastPart}, ".")
|
||||
}
|
||||
|
||||
fmt.Printf("process recommend:%s\n", recommend)
|
||||
recommends = append(recommends, recommend)
|
||||
}
|
||||
}
|
||||
fmt.Println("--------------")
|
||||
fmt.Printf("recommends:%v\n", recommends)
|
||||
fmt.Printf("len of recommends:%d\n", len(recommends))
|
||||
|
||||
return recommends, nil
|
||||
}
|
||||
return []string{}, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue