Drop the score filter and instead limit result quantity in similar_features()
This commit is contained in:
parent
863c49575f
commit
3563cc8135
|
@ -14,7 +14,7 @@ class AuthorityRecord(models.Model):
|
|||
class FeatureSearchManager(models.GeoManager):
|
||||
def set_threshold(self, threshold):
|
||||
"""Set the limit for trigram similarity matching."""
|
||||
cursor = connection.cursor
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
||||
|
||||
def overlaps(self, (minx, miny, maxx, maxy), text=None, srid=4326):
|
||||
|
@ -69,7 +69,7 @@ class Feature(models.Model):
|
|||
return ''
|
||||
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()
|
||||
name = unicode(self).replace("'", "''") # escape '
|
||||
cursor.execute("""
|
||||
|
@ -82,11 +82,11 @@ class Feature(models.Model):
|
|||
WHERE geometry && st_buffer('%s', %f)
|
||||
AND preferred_name %%%% '%s'
|
||||
AND id <> %d
|
||||
LIMIT %d
|
||||
) AS whatever
|
||||
WHERE %f * similarity / (distance + 1.0) >= 1.0
|
||||
ORDER BY similarity / (distance + 1.0) DESC"""
|
||||
% (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 = []
|
||||
fields = ('id', 'url', 'preferred_name', 'feature_type_id', 'admin1', 'admin2', 'is_primary')
|
||||
|
|
Loading…
Reference in New Issue
Block a user