trigram / alt names

This commit is contained in:
Sanj 2012-10-05 16:52:29 +05:30
parent 96582f212e
commit 3312e2f258
2 changed files with 10 additions and 3 deletions

View File

@ -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]
})

View File

@ -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")