Drop the score filter and instead limit result quantity in similar_features()
This commit is contained in:
parent
863c49575f
commit
3563cc8135
1 changed files with 4 additions and 4 deletions
|
@ -14,7 +14,7 @@ class AuthorityRecord(models.Model):
|
||||||
class FeatureSearchManager(models.GeoManager):
|
class FeatureSearchManager(models.GeoManager):
|
||||||
def set_threshold(self, threshold):
|
def set_threshold(self, threshold):
|
||||||
"""Set the limit for trigram similarity matching."""
|
"""Set the limit for trigram similarity matching."""
|
||||||
cursor = connection.cursor
|
cursor = connection.cursor()
|
||||||
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
||||||
|
|
||||||
def overlaps(self, (minx, miny, maxx, maxy), text=None, srid=4326):
|
def overlaps(self, (minx, miny, maxx, maxy), text=None, srid=4326):
|
||||||
|
@ -69,7 +69,7 @@ class Feature(models.Model):
|
||||||
return ''
|
return ''
|
||||||
time_end.short_description = "End Date"
|
time_end.short_description = "End Date"
|
||||||
|
|
||||||
def similar_features(self, max_distance=15000, scale_factor=2000):
|
def similar_features(self, max_distance=15000, scale_factor=2000, limit=20):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
name = unicode(self).replace("'", "''") # escape '
|
name = unicode(self).replace("'", "''") # escape '
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
|
@ -82,11 +82,11 @@ class Feature(models.Model):
|
||||||
WHERE geometry && st_buffer('%s', %f)
|
WHERE geometry && st_buffer('%s', %f)
|
||||||
AND preferred_name %%%% '%s'
|
AND preferred_name %%%% '%s'
|
||||||
AND id <> %d
|
AND id <> %d
|
||||||
|
LIMIT %d
|
||||||
) AS whatever
|
) AS whatever
|
||||||
WHERE %f * similarity / (distance + 1.0) >= 1.0
|
|
||||||
ORDER BY similarity / (distance + 1.0) DESC"""
|
ORDER BY similarity / (distance + 1.0) DESC"""
|
||||||
% (scale_factor, name, self.geometry.wkt, self.geometry.wkt,
|
% (scale_factor, name, self.geometry.wkt, self.geometry.wkt,
|
||||||
max_distance*0.00001, name, self.id, scale_factor)
|
max_distance*0.00001, name, self.id, limit)
|
||||||
)
|
)
|
||||||
result_list = []
|
result_list = []
|
||||||
fields = ('id', 'url', 'preferred_name', 'feature_type_id', 'admin1', 'admin2', 'is_primary')
|
fields = ('id', 'url', 'preferred_name', 'feature_type_id', 'admin1', 'admin2', 'is_primary')
|
||||||
|
|
Loading…
Add table
Reference in a new issue