From da73dfa1b337a75ecdbae03ba019502484e9f7a6 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Tue, 30 Aug 2011 17:47:57 -0700 Subject: [PATCH] Add threshold to find(). --- gazetteer/places/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py index f097f7f..b0e625b 100644 --- a/gazetteer/places/views.py +++ b/gazetteer/places/views.py @@ -10,21 +10,30 @@ def search(request): def search_json(request): search_term = request.GET.get("search", "") + threshold = request.GET.get("threshold", None) bbox = request.GET.get("bbox", False) country = request.GET.get("adm0", "US") # right now, unused adm1 = request.GET.get("adm1", "") adm2 = request.GET.get("adm2", "") srid = int(request.GET.get("srid", 4326)) + if threshold: + try: + threshold = float(threshold) + except ValueError: + return render_to_json_response({'error': 'threshold must be a float'}) + if bbox: try: bbox = map(float, bbox.split(",")) except ValueError: bbox = None + return render_to_json_response({'error': 'bbox must be in the form: minx,miny,maxx,maxy'}) + if not bbox and not search_term: return render_to_json_response({'error': 'must supply either a valid `bbox` or a `search` parameter'}) - features_qset = Feature.search.find(bbox=bbox, text=search_term, adm1=adm1, adm2=adm2, srid=srid)[0:20] + features_qset = Feature.search.find(bbox=bbox, text=search_term, threshold=threshold, adm1=adm1, adm2=adm2, srid=srid)[0:20] features = [f.get_geojson(srid) for f in features_qset] d = { 'type': 'FeatureCollection',