[mb-commits] r9886 - search_server/trunk/lib

root at musicbrainz.org root at musicbrainz.org
Thu Jun 26 08:01:43 UTC 2008


Author: robert
Date: 2008-06-26 08:01:43 +0000 (Thu, 26 Jun 2008)
New Revision: 9886

Modified:
   search_server/trunk/lib/artistsearch.py
   search_server/trunk/lib/labelsearch.py
   search_server/trunk/lib/search.py
Log:
Sort by relevance first, then by value. This allows shorter fields to rise to the top of equal results.


Modified: search_server/trunk/lib/artistsearch.py
===================================================================
--- search_server/trunk/lib/artistsearch.py	2008-06-26 08:00:09 UTC (rev 9885)
+++ search_server/trunk/lib/artistsearch.py	2008-06-26 08:01:43 UTC (rev 9886)
@@ -90,7 +90,7 @@
        '''
 
        out = '<artist-list count="%d" offset="%d">' % (count, offset)
-       for doc in hits:
+       for i, doc in enumerate(hits):
            artist = doc.get('artist') or u''
            sortname = doc.get('sortname') or u''
            artype = doc.get('type') or u''

Modified: search_server/trunk/lib/labelsearch.py
===================================================================
--- search_server/trunk/lib/labelsearch.py	2008-06-26 08:00:09 UTC (rev 9885)
+++ search_server/trunk/lib/labelsearch.py	2008-06-26 08:01:43 UTC (rev 9886)
@@ -74,9 +74,7 @@
        if rel: out += u'<td>Rel</td>'
        out += u'</tr>'
        
-       for i in xrange(offset, min(count, count + offset)):
-           doc = hits.doc(i)
-
+       for i, doc in enumerate(hits):
            label = doc.get('label') or u''
            sortname = doc.get('sortname') or u''
            comment = doc.get('comment') or u''
@@ -104,9 +102,7 @@
        '''
 
        out = '<label-list count="%d" offset="%d">' % (count, offset)
-       for i in xrange(offset, min(count, count + offset)):
-           doc = hits.doc(i)
-
+       for i, doc in enumerate(hits):
            label = doc.get('label') or u''
            sortname = doc.get('sortname') or u''
            type = doc.get('type') or u''

Modified: search_server/trunk/lib/search.py
===================================================================
--- search_server/trunk/lib/search.py	2008-06-26 08:00:09 UTC (rev 9885)
+++ search_server/trunk/lib/search.py	2008-06-26 08:01:43 UTC (rev 9886)
@@ -84,11 +84,13 @@
         self.weight = xapian.BM25Weight(0, 0, 1, .1, .5);
         self.en = enquire = xapian.Enquire(self.index)
         self.en.set_weighting_scheme(self.weight)
-        self.en.set_sort_by_relevance_then_value(0, True)
+        #self.en.set_docid_order(xapian.Enquire.DONT_CARE)
+        self.en.set_sort_by_relevance_then_value(0, False)
 
         self.qp = xapian.QueryParser()
         self.qp.set_database(self.index)
         self.qp.set_stemming_strategy(xapian.QueryParser.STEM_NONE)
+	self.qp.set_default_op(xapian.Query.OP_AND)
 
     def close(self):
 	'''
@@ -253,7 +255,8 @@
 	    parsedQuery = self.qp.parse_query(query, 
 			      	              xapian.QueryParser.FLAG_PHRASE | 
 				              xapian.QueryParser.FLAG_BOOLEAN | 
-				              xapian.QueryParser.FLAG_LOVEHATE,
+				              xapian.QueryParser.FLAG_LOVEHATE |
+				              xapian.QueryParser.FLAG_PURE_NOT,
 				              self.defaultField)
         except xapian.Error, msg:
 	    text = str(msg)
@@ -294,7 +297,7 @@
         if maxHits < 1: maxHits = MAX_HITS
         (hits, total) = self.queryIndex(query, offset, maxHits);
         redirect = ""
-        if len(hits) == 1:
+        if total == 1:
            doc = hits[0]
            redirect = doc.get('trid')
            if not redirect: redirect = doc.get('reid')




More information about the MusicBrainz-commits mailing list