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):
|
def __unicode__(self):
|
||||||
return self.preferred_name
|
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):
|
def overlaps(self, bbox, text=None):
|
||||||
bbox = 'POLYGON(((%f %f, %f %f, %f %f, %f %f, %f %f)))' %
|
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[1], bbox[2], bbox[1], bbox[2], bbox[3],
|
||||||
bbox[0], bbox[3], bbox[0], bbox[1])
|
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:
|
if text:
|
||||||
text = text.replace("'", "''") # escape the '
|
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
|
return qset
|
||||||
|
|
||||||
class Feature(models.Model):
|
class Feature(models.Model):
|
||||||
|
@ -33,7 +39,7 @@ class Feature(models.Model):
|
||||||
time_frame = models.ForeignKey("TimeFrame", null=True, blank=True)
|
time_frame = models.ForeignKey("TimeFrame", null=True, blank=True)
|
||||||
relationships = models.ManyToManyField("Feature", through='Relationship', blank=True)
|
relationships = models.ManyToManyField("Feature", through='Relationship', blank=True)
|
||||||
objects = models.GeoManager()
|
objects = models.GeoManager()
|
||||||
search = models.GeoSearchManager()
|
search = models.FeatureSearchManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['preferred_name']
|
ordering = ['preferred_name']
|
||||||
|
|
Loading…
Reference in New Issue
Block a user