mirror of
https://github.com/Dvorinka/facr-scraper.git
synced 2026-06-05 04:52:56 +00:00
efsf
This commit is contained in:
@@ -336,8 +336,6 @@ func parseCompetitionMatchesFromIS(detailURL, clubType, clubName, clubID string)
|
|||||||
}
|
}
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Logo resolution via local /club/search with simple in-memory cache ---
|
|
||||||
var logoCache = map[string]string{}
|
var logoCache = map[string]string{}
|
||||||
|
|
||||||
type searchAPIResult struct {
|
type searchAPIResult struct {
|
||||||
@@ -347,6 +345,23 @@ type searchAPIResult struct {
|
|||||||
} `json:"results"`
|
} `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simplifyClubQuery takes a full club name like "FK Kofola Krnov" and returns
|
||||||
|
// a simplified search token like "krnov" to improve chances of finding a logo.
|
||||||
|
func simplifyClubQuery(name string) string {
|
||||||
|
s := strings.TrimSpace(name)
|
||||||
|
if s == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
parts := strings.Fields(s)
|
||||||
|
if len(parts) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// Use the last word (often the city), strip simple punctuation, lowercased
|
||||||
|
last := parts[len(parts)-1]
|
||||||
|
last = strings.Trim(last, ",.;:-()[]{}\"'`“”’")
|
||||||
|
return strings.ToLower(last)
|
||||||
|
}
|
||||||
|
|
||||||
func getLogoBySearch(name string) string {
|
func getLogoBySearch(name string) string {
|
||||||
key := strings.ToLower(strings.TrimSpace(name))
|
key := strings.ToLower(strings.TrimSpace(name))
|
||||||
if key == "" {
|
if key == "" {
|
||||||
@@ -355,23 +370,39 @@ func getLogoBySearch(name string) string {
|
|||||||
if v, ok := logoCache[key]; ok {
|
if v, ok := logoCache[key]; ok {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
// Query local API
|
|
||||||
apiURL := fmt.Sprintf("http://localhost:8080/club/search?q=%s", neturl.QueryEscape(name))
|
|
||||||
client := &http.Client{Timeout: 5 * time.Second}
|
client := &http.Client{Timeout: 5 * time.Second}
|
||||||
resp, err := client.Get(apiURL)
|
// Prefer simplified last-word token (e.g., "krnov") to improve hit rate for logos
|
||||||
|
query := simplifyClubQuery(name)
|
||||||
|
if query == "" {
|
||||||
|
query = name
|
||||||
|
}
|
||||||
|
|
||||||
|
doSearch := func(q string) (searchAPIResult, bool) {
|
||||||
|
url := fmt.Sprintf("http://localhost:8080/club/search?q=%s", neturl.QueryEscape(q))
|
||||||
|
resp, err := client.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return searchAPIResult{}, false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
// drain body to allow reuse
|
|
||||||
io.Copy(io.Discard, resp.Body)
|
io.Copy(io.Discard, resp.Body)
|
||||||
return ""
|
return searchAPIResult{}, false
|
||||||
}
|
}
|
||||||
var payload searchAPIResult
|
var payload searchAPIResult
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
|
||||||
|
return searchAPIResult{}, false
|
||||||
|
}
|
||||||
|
return payload, true
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, ok := doSearch(query)
|
||||||
|
if !ok || len(payload.Results) == 0 {
|
||||||
|
// Fallback to full name if simplified token yields nothing
|
||||||
|
payload, ok = doSearch(name)
|
||||||
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// pick best match: exact (case-insensitive), then contains, else first
|
// pick best match: exact (case-insensitive), then contains, else first
|
||||||
best := ""
|
best := ""
|
||||||
for _, r := range payload.Results {
|
for _, r := range payload.Results {
|
||||||
|
|||||||
Reference in New Issue
Block a user