fix: suppress fallback recommendations when concrete hits exist
- detect concrete recommend hits before normalizing results - drop fallback results when any syntax path returns real candidates - keep fallback candidates only when every path has no concrete hit
This commit is contained in:
parent
33eb2d9be8
commit
305bdd4dcf
|
|
@ -124,6 +124,7 @@ func levelOneRedisSearch(ctx context.Context, rdb *redis.Client, hierarchy const
|
|||
func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchResult {
|
||||
rdb := diagram.GetRedisClientInstance()
|
||||
finalizeResults := func(results map[string]SearchResult) map[string]SearchResult {
|
||||
results = suppressFallbackResultsWhenConcreteHitExists(results)
|
||||
return normalizeRecommendResults(input, results)
|
||||
}
|
||||
|
||||
|
|
@ -281,6 +282,27 @@ func RedisSearchRecommend(ctx context.Context, input string) map[string]SearchRe
|
|||
}
|
||||
}
|
||||
|
||||
func suppressFallbackResultsWhenConcreteHitExists(results map[string]SearchResult) map[string]SearchResult {
|
||||
hasConcreteHit := false
|
||||
for _, result := range results {
|
||||
if result.Err == nil && !result.IsFallback && len(result.QueryDatas) > 0 {
|
||||
hasConcreteHit = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !hasConcreteHit {
|
||||
return results
|
||||
}
|
||||
|
||||
for key, result := range results {
|
||||
if result.IsFallback {
|
||||
delete(results, key)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
func normalizeRecommendResults(input string, results map[string]SearchResult) map[string]SearchResult {
|
||||
for key, result := range results {
|
||||
if result.Err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue