From 3563cc813520929d79912e55a21be6dbbec7098c Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Sun, 28 Aug 2011 10:11:44 +0200 Subject: [PATCH] Drop the score filter and instead limit result quantity in similar_features() --- gazetteer/places/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gazetteer/places/models.py b/gazetteer/places/models.py index ae0b47d..b001034 100644 --- a/gazetteer/places/models.py +++ b/gazetteer/places/models.py @@ -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')