Mercurial > gemma
changeset 748:3cb012d4d9ef
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.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Mon, 24 Sep 2018 16:19:31 +0200 |
parents | e33012c0aa7e |
children | 802ecaae8410 |
files | pkg/controllers/search.go |
diffstat | 1 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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