trigram / alt names
This commit is contained in:
parent
96582f212e
commit
3312e2f258
|
@ -66,14 +66,20 @@ def areas(request):
|
||||||
|
|
||||||
def stops(request):
|
def stops(request):
|
||||||
q = request.GET.get("q", "")
|
q = request.GET.get("q", "")
|
||||||
|
ctype = ContentType.objects.get_for_model(Stop)
|
||||||
|
stops = []
|
||||||
if q != '':
|
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:
|
else:
|
||||||
qset = Stop.objects.all()
|
stops = Stop.objects.all()
|
||||||
srid = int(request.GET.get("srid", 4326))
|
srid = int(request.GET.get("srid", 4326))
|
||||||
return render_to_json_response({
|
return render_to_json_response({
|
||||||
'type': 'FeatureCollection',
|
'type': 'FeatureCollection',
|
||||||
'features': [stop.get_geojson(srid=srid) for stop in qset]
|
'features': [stop.get_geojson(srid=srid) for stop in stops]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -426,6 +426,7 @@ ALT_TYPE_CHOICES = (
|
||||||
)
|
)
|
||||||
|
|
||||||
class AlternativeName(models.Model):
|
class AlternativeName(models.Model):
|
||||||
|
objects = TrigramSearchManager(('name',))
|
||||||
name = models.CharField(max_length=512)
|
name = models.CharField(max_length=512)
|
||||||
name_mr = models.CharField(max_length=512, blank=True)
|
name_mr = models.CharField(max_length=512, blank=True)
|
||||||
typ = models.CharField(max_length=64, choices=ALT_TYPE_CHOICES, default="alt")
|
typ = models.CharField(max_length=64, choices=ALT_TYPE_CHOICES, default="alt")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user