From 157012b9f58464e2f638a3d6aa8cf18a99c21080 Mon Sep 17 00:00:00 2001 From: etwas Date: Tue, 15 Apr 2025 21:45:13 +0200 Subject: [PATCH] feat: make api more useful for usage in search bars and the like --- main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2b0b897..25dfe17 100644 --- a/main.go +++ b/main.go @@ -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