mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-07 20:08:02 -06:00
FilterLocations string filtering implementation
This commit is contained in:
14
helpers.go
14
helpers.go
@@ -112,6 +112,20 @@ func FilterLocations(all_locations []Location, query string, limit int, seed_val
|
||||
return randomized
|
||||
}
|
||||
|
||||
lower_query := strings.ToLower(query)
|
||||
filtered_locations := make([]Location, 0, limit)
|
||||
matches := 0
|
||||
|
||||
for _, location := range all_locations {
|
||||
if strings.Contains(strings.ToLower(location.name), lower_query) {
|
||||
filtered_locations = append(filtered_locations, location)
|
||||
matches++
|
||||
|
||||
if matches >= limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filtered_locations
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user