[ckan-changes] commit/ckanext-solr: pudo: fix ordering of result set by applying scored order after retrieval from database.

Bitbucket commits-noreply at bitbucket.org
Wed Aug 3 11:14:14 UTC 2011


1 new changeset in ckanext-solr:

http://bitbucket.org/okfn/ckanext-solr/changeset/76ebb12bd973/
changeset:   76ebb12bd973
user:        pudo
date:        2011-08-03 13:14:03
summary:     fix ordering of result set by applying scored order after retrieval from database.
affected #:  1 file (65 bytes)

--- a/ckanext/solr/backend.py	Thu Jun 09 21:31:20 2011 +0200
+++ b/ckanext/solr/backend.py	Wed Aug 03 13:14:03 2011 +0200
@@ -31,8 +31,9 @@
             fq += " +(%s) " % licenses
         
         order_by = self.options.order_by
-        if order_by == 'rank': order_by = 'score'
-        
+        if order_by == 'rank' or order_by is None: 
+            order_by = 'score,title'
+
         # show only results from this CKAN instance:
         fq = fq + " +site_id:\"%s\" " % config.get('ckan.site_id')
 
@@ -53,7 +54,7 @@
             data = conn.query(query,
                               fq=fq, 
                               # make sure data.facet_counts is set:
-                              facet='true',                               
+                              facet='true',
                               facet_limit=facet_limit,
                               facet_field=self.facet_by,
                               facet_mincount=1,
@@ -71,11 +72,11 @@
             conn.close()
         
         self.count = int(data.numFound)
-        result_ids = [(r.get('id')) for r in data.results]
+        scores = dict([(r.get('id'), r.get('score')) for r in data.results])
         q = Authorizer().authorized_query(self.options.username, model.Package)
-        q = q.filter(model.Package.id.in_(result_ids))
+        q = q.filter(model.Package.id.in_(scores.keys()))
         self.facets = data.facet_counts.get('facet_fields', {})
-        self.results = q.all()
+        self.results = sorted(q, key=lambda r: scores[r.id], reverse=True)
 
     
 class SolrSearchIndex(SearchIndex):

Repository URL: https://bitbucket.org/okfn/ckanext-solr/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list