changeset 5209:b072085c6acd

search: improve search result ordering (details below) Title search orders by pagename. Now we also consider the attachment name, so that a page hit comes first and is followed by hits for attachments of that page. Full text search is ordering by hit weight and pagename. Now we also consider the attachment name there, so that if weight and pagename is same, the page hit will come first and is followed by hits for attachments of that page. This might be a rather rare case, because usually weight is not the same, but we do it for consistency with title search.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 04 Oct 2009 14:37:59 +0200
parents 76fac2e548a7
children e167f58601ef
files MoinMoin/search/results.py
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/results.py	Sun Oct 04 04:03:43 2009 +0200
+++ b/MoinMoin/search/results.py	Sun Oct 04 14:37:59 2009 +0200
@@ -252,16 +252,16 @@
 
     def _sortByWeight(self):
         """ Sorts found pages by the weight of the matches """
-        tmp = [(hit.weight(), hit.page_name, hit) for hit in self.hits]
+        tmp = [(hit.weight(), hit.page_name, hit.attachment, hit) for hit in self.hits]
         tmp.sort()
         tmp.reverse()
-        self.hits = [item[2] for item in tmp]
+        self.hits = [item[3] for item in tmp]
 
     def _sortByPagename(self):
-        """ Sorts a list of found pages alphabetical by page name """
-        tmp = [(hit.page_name, hit) for hit in self.hits]
+        """ Sorts a list of found pages alphabetical by page/attachment name """
+        tmp = [(hit.page_name, hit.attachment, hit) for hit in self.hits]
         tmp.sort()
-        self.hits = [item[1] for item in tmp]
+        self.hits = [item[2] for item in tmp]
 
     def stats(self, request, formatter, hitsFrom):
         """ Return search statistics, formatted with formatter