Fix up (renamed) FeatureSearchManager; add set_threshold
This commit is contained in:
parent
5ed7e0f0b5
commit
a6dfee7375
|
@ -10,15 +10,21 @@ class AuthorityRecord(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.preferred_name
|
||||
|
||||
class GeoSearchManager(manager.GeoManager):
|
||||
class FeatureSearchManager(manager.GeoManager):
|
||||
def set_threshold(self, threshold):
|
||||
"""Set the limit for trigram similarity matching."""
|
||||
cursor = connection.cursor
|
||||
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
||||
|
||||
def overlaps(self, bbox, text=None):
|
||||
bbox = 'POLYGON(((%f %f, %f %f, %f %f, %f %f, %f %f)))' %
|
||||
(bbox[0], bbox[1], bbox[2], bbox[1], bbox[2], bbox[3],
|
||||
bbox[0], bbox[3], bbox[0], bbox[1])
|
||||
qset = super(GeoSearchManager, self).get_query_set().filter(geometry_bboverlaps=bbox)
|
||||
qset = super(FeatureSearchManager, self).get_query_set().filter(geometry_bboverlaps=bbox)
|
||||
if text:
|
||||
text = text.replace("'", "''") # escape the '
|
||||
qset = qset.extra(where="preferred_name %% '%s'" % text)
|
||||
# use the pg_trgm index
|
||||
qset = qset.extra(where=["preferred_name %% '%s']" % text)
|
||||
return qset
|
||||
|
||||
class Feature(models.Model):
|
||||
|
@ -33,7 +39,7 @@ class Feature(models.Model):
|
|||
time_frame = models.ForeignKey("TimeFrame", null=True, blank=True)
|
||||
relationships = models.ManyToManyField("Feature", through='Relationship', blank=True)
|
||||
objects = models.GeoManager()
|
||||
search = models.GeoSearchManager()
|
||||
search = models.FeatureSearchManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['preferred_name']
|
||||
|
|
Loading…
Reference in New Issue
Block a user