Add abbreviations.

This commit is contained in:
Schuyler Erle 2011-08-31 03:19:51 -07:00
parent c5501c7ff6
commit 3a09d2d314

View File

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