# HG changeset patch # User Sascha Wilde # Date 1537798771 -7200 # Node ID 3cb012d4d9ef1964a70c7064dae2fcb56f943948 # Parent e33012c0aa7e30b43fb34e8ecf1742d4de3a53d2 Added search for bottlenecks As we only implement search for rkm an and bottlenecks for now, this is the default if the search string is not a (potential) rkm number. diff -r e33012c0aa7e -r 3cb012d4d9ef pkg/controllers/search.go --- a/pkg/controllers/search.go Mon Sep 24 16:03:25 2018 +0200 +++ b/pkg/controllers/search.go Mon Sep 24 16:19:31 2018 +0200 @@ -16,7 +16,12 @@ FROM (SELECT location_code::text AS name, ST_AsGeoJSON(geom)::json AS geom FROM waterway.distance_marks - WHERE (location_code).hectometre = $1) r` + WHERE (location_code).hectometre = $1) r` + searchBottleneckSQL = `SELECT json_agg(r) +FROM (SELECT objnam AS name, + ST_AsGeoJSON(ST_Centroid(area))::json AS geom + FROM waterway.bottlenecks + WHERE objnam ILIKE $1) r` ) var rkmRegex = regexp.MustCompile( @@ -77,12 +82,28 @@ jr.Result = strings.NewReader(result) } else { - err = JSONError{ - Code: http.StatusNotFound, - Message: fmt.Sprintf("No Results for %s.", - s.SearchString), + var result string + + err = db.QueryRowContext( + req.Context(), + searchBottleneckSQL, + "%"+s.SearchString+"%", + ).Scan(&result) + + switch { + case err == sql.ErrNoRows: + err = JSONError{ + Code: http.StatusNotFound, + Message: fmt.Sprintf("No Results for %s.", + s.SearchString), + } + return + case err != nil: + return } + jr.Result = strings.NewReader(result) + } return