From 3312e2f25886835de4cdd56d64dd076468d56528 Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 5 Oct 2012 16:52:29 +0530 Subject: [PATCH] trigram / alt names --- chaloBEST/mumbai/apiviews.py | 12 +++++++++--- chaloBEST/mumbai/models.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 2765641..09e0b6a 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -66,14 +66,20 @@ def areas(request): def stops(request): q = request.GET.get("q", "") + ctype = ContentType.objects.get_for_model(Stop) + stops = [] if q != '': - qset = Stop.objects.find_approximate(q, TRIGRAM_THRESHOLD) + alt_name_matches = AlternativeName.objects.find_approximate(q, TRIGRAM_THRESHOLD).filter(content_type=ctype) + for alt_name in alt_name_matches: + stop = alt_name.content_object + if stop not in stops: + stops.append(stop) else: - qset = Stop.objects.all() + stops = Stop.objects.all() srid = int(request.GET.get("srid", 4326)) return render_to_json_response({ 'type': 'FeatureCollection', - 'features': [stop.get_geojson(srid=srid) for stop in qset] + 'features': [stop.get_geojson(srid=srid) for stop in stops] }) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 89e63b6..c4025ff 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -426,6 +426,7 @@ ALT_TYPE_CHOICES = ( ) class AlternativeName(models.Model): + objects = TrigramSearchManager(('name',)) name = models.CharField(max_length=512) name_mr = models.CharField(max_length=512, blank=True) typ = models.CharField(max_length=64, choices=ALT_TYPE_CHOICES, default="alt")