From 960eb21283d00a83162b658f91aee69015a65048 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Sun, 28 Aug 2011 09:37:21 +0200 Subject: [PATCH] Order overlaps results by similarity if text is provideed. --- gazetteer/places/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gazetteer/places/models.py b/gazetteer/places/models.py index be19080..23a2731 100644 --- a/gazetteer/places/models.py +++ b/gazetteer/places/models.py @@ -24,7 +24,9 @@ class FeatureSearchManager(models.GeoManager): if text: text = text.replace("'", "''") # escape the ' # 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 class Feature(models.Model):