Add threshold to find().

This commit is contained in:
Schuyler Erle 2011-08-30 17:47:57 -07:00
parent a9c5064c95
commit da73dfa1b3

View File

@ -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',