FilterLocations string filtering implementation

This commit is contained in:
2023-12-12 01:41:53 -06:00
parent c6b83b883c
commit 2e7460e658

View File

@@ -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
}