feat: make api more useful for usage in search bars and the like

This commit is contained in:
etwas 2025-04-15 21:45:13 +02:00
parent 1ff513ebae
commit 157012b9f5
Signed by: etwas
SSH key fingerprint: SHA256:bHhIeAdn/2k9jmOs6+u6ox98VYmoHUN3HfnpV2w8Ws0

15
main.go
View file

@ -103,8 +103,19 @@ func (h *stopInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if r.FormValue("exact") != "true" {
searchQuery = "%" + searchQuery + "%"
var searchQueries = strings.Split(searchQuery, " ")
for i, query := range searchQueries {
if i == 0 {
// Parse whether result shall be exact
if r.FormValue("contains") != "true" {
searchQueries[0] = "%" + query + "%"
} else {
searchQueries[0] = query + "%"
}
} else {
searchQueries[i] = "%" + query + "%"
}
}
var longDistance pgtype.Bool