Mercurial > gemma
comparison pkg/controllers/search.go @ 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 | 6fe6839f5ce6 |
children | 802ecaae8410 |
comparison
equal
deleted
inserted
replaced
747:e33012c0aa7e | 748:3cb012d4d9ef |
---|---|
14 const ( | 14 const ( |
15 searchHectometreSQL = `SELECT json_agg(r) | 15 searchHectometreSQL = `SELECT json_agg(r) |
16 FROM (SELECT location_code::text AS name, | 16 FROM (SELECT location_code::text AS name, |
17 ST_AsGeoJSON(geom)::json AS geom | 17 ST_AsGeoJSON(geom)::json AS geom |
18 FROM waterway.distance_marks | 18 FROM waterway.distance_marks |
19 WHERE (location_code).hectometre = $1) r` | 19 WHERE (location_code).hectometre = $1) r` |
20 searchBottleneckSQL = `SELECT json_agg(r) | |
21 FROM (SELECT objnam AS name, | |
22 ST_AsGeoJSON(ST_Centroid(area))::json AS geom | |
23 FROM waterway.bottlenecks | |
24 WHERE objnam ILIKE $1) r` | |
20 ) | 25 ) |
21 | 26 |
22 var rkmRegex = regexp.MustCompile( | 27 var rkmRegex = regexp.MustCompile( |
23 "^[[:space:]]*([0-9]+)([,.]([0-9]))?[[:space:]]*$", | 28 "^[[:space:]]*([0-9]+)([,.]([0-9]))?[[:space:]]*$", |
24 ) | 29 ) |
75 return | 80 return |
76 } | 81 } |
77 | 82 |
78 jr.Result = strings.NewReader(result) | 83 jr.Result = strings.NewReader(result) |
79 } else { | 84 } else { |
80 err = JSONError{ | 85 var result string |
81 Code: http.StatusNotFound, | 86 |
82 Message: fmt.Sprintf("No Results for %s.", | 87 err = db.QueryRowContext( |
83 s.SearchString), | 88 req.Context(), |
89 searchBottleneckSQL, | |
90 "%"+s.SearchString+"%", | |
91 ).Scan(&result) | |
92 | |
93 switch { | |
94 case err == sql.ErrNoRows: | |
95 err = JSONError{ | |
96 Code: http.StatusNotFound, | |
97 Message: fmt.Sprintf("No Results for %s.", | |
98 s.SearchString), | |
99 } | |
100 return | |
101 case err != nil: | |
102 return | |
84 } | 103 } |
104 | |
105 jr.Result = strings.NewReader(result) | |
85 | 106 |
86 } | 107 } |
87 | 108 |
88 return | 109 return |
89 } | 110 } |