mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
dev day #89
This commit is contained in:
@@ -452,6 +452,47 @@ func (fc *FACRController) SearchClubs(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(results) > 1 {
|
||||
unique := make([]SearchResult, 0, len(results))
|
||||
seenByID := map[string]int{}
|
||||
seenByName := map[string]int{}
|
||||
normKey := func(s string) string {
|
||||
x := strings.ToLower(strings.TrimSpace(s))
|
||||
x = strings.ReplaceAll(x, ".", "")
|
||||
x = strings.ReplaceAll(x, " ", "")
|
||||
return x
|
||||
}
|
||||
for _, r := range results {
|
||||
id := strings.TrimSpace(r.ClubID)
|
||||
if id != "" {
|
||||
if idx, ok := seenByID[id]; ok {
|
||||
// Keep the one with a logo
|
||||
if strings.TrimSpace(unique[idx].LogoURL) == "" && strings.TrimSpace(r.LogoURL) != "" {
|
||||
unique[idx] = r
|
||||
}
|
||||
continue
|
||||
}
|
||||
seenByID[id] = len(unique)
|
||||
unique = append(unique, r)
|
||||
continue
|
||||
}
|
||||
key := normKey(r.Name)
|
||||
if key == "" {
|
||||
unique = append(unique, r)
|
||||
continue
|
||||
}
|
||||
if idx, ok := seenByName[key]; ok {
|
||||
if strings.TrimSpace(unique[idx].LogoURL) == "" && strings.TrimSpace(r.LogoURL) != "" {
|
||||
unique[idx] = r
|
||||
}
|
||||
continue
|
||||
}
|
||||
seenByName[key] = len(unique)
|
||||
unique = append(unique, r)
|
||||
}
|
||||
results = unique
|
||||
}
|
||||
|
||||
// respond and close the function
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"query": q,
|
||||
|
||||
Reference in New Issue
Block a user