Order overlaps results by similarity if text is provideed.

This commit is contained in:
Schuyler Erle 2011-08-28 09:37:21 +02:00
parent abd06fc0e2
commit 960eb21283

View File

@ -24,7 +24,9 @@ class FeatureSearchManager(models.GeoManager):
if text: if text:
text = text.replace("'", "''") # escape the ' text = text.replace("'", "''") # escape the '
# use the pg_trgm index # use the pg_trgm index
qset = qset.extra(where=["preferred_name %%%% '%s'" % text]) qset = qset.extra(select={"similarity":"similarity(preferred_name, '%s')" % text},
where=["preferred_name %%%% '%s'" % text],
order_by=["-similarity"])
return qset return qset
class Feature(models.Model): class Feature(models.Model):