From 3a09d2d314acf88406dd4c87cf05e632ecd2de41 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Wed, 31 Aug 2011 03:19:51 -0700 Subject: [PATCH] Add abbreviations. --- gazetteer/places/models.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gazetteer/places/models.py b/gazetteer/places/models.py index f214fea..f84e560 100644 --- a/gazetteer/places/models.py +++ b/gazetteer/places/models.py @@ -24,7 +24,7 @@ class FeatureSearchManager(models.GeoManager): cursor = connection.cursor() cursor.execute("""SELECT set_limit(%f)""" % threshold) - def find(self, bbox=None, text=None, adm1=None, adm2=None srid=4326): + def find(self, bbox=None, text=None, adm1=None, adm2=None, threshold=0.35, srid=4326): qset = self.get_query_set() if bbox: (minx, miny, maxx, maxy) = bbox @@ -32,6 +32,7 @@ class FeatureSearchManager(models.GeoManager): if srid != 4326: bbox.transform(4326) # convert to lon/lat qset = qset.filter(geometry__bboverlaps=bbox) if text: + self.set_threshold(threshold) text = text.replace("'", "''") # escape the ' # use the pg_trgm index qset = qset.extra(select={"similarity":"similarity(preferred_name, '%s')"}, @@ -144,9 +145,10 @@ LANGUAGE_CHOICES = ( NAME_TYPE_CHOICES = ( ('alternate', 'alternate'), - ('official', 'official'), - ('historic', 'historic'), + ('abbreviation', 'abbreviation'), ('colloquial', 'colloquial'), + ('historic', 'historic'), + ('official', 'official'), ('icao', 'ICAO code'), ('iata', 'IATA code'), ('postcode', 'ZIP code'), @@ -205,12 +207,12 @@ RELATIONSHIP_CHOICES = ( ) class Relationship(models.Model): - feature1 = models.ForeignKey(Feature, related_name="feauture_from") + feature1 = models.ForeignKey(Feature, related_name="feature_from") feature2 = models.ForeignKey(Feature, related_name="feature_to") relationship_type = models.CharField(max_length=64, choices=RELATIONSHIP_CHOICES) def __unicode__(self): - return "%s: %s to %s" % (self.relationship_type, self.feature1.preferred_name, self.feature2.preferred_name,) + return "%s %s %s" % (self.feature1.preferred_name, self.relationship_type, self.feature2.preferred_name,) class Meta: verbose_name = "Relation"