[yum-commits] Branch 'yum-3_2_X' - 2 commits - cli.py yum/__init__.py

Ville Skyttä scop at osuosl.org
Mon Oct 26 21:51:34 UTC 2009


 cli.py          |    4 +++-
 yum/__init__.py |   14 ++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 3053a5fd2fa842142a9e66bbcaa1c40b736bc75b
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Mon Oct 26 23:47:55 2009 +0200

    Print search strings in the order they were passed.

diff --git a/cli.py b/cli.py
index 5eed6c4..9eed20d 100644
--- a/cli.py
+++ b/cli.py
@@ -803,7 +803,9 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
             if keys != okeys:
                 if akeys:
                     print ""
-                print self.fmtSection("Matched: " + ", ".join(sorted(keys)))
+                # Print them in the order they were passed
+                used_keys = [arg for arg in args if arg in keys]
+                print self.fmtSection("Matched: " + ", ".join(used_keys))
                 okeys = keys
                 akeys.update(keys)
             self.matchcallback(po, matched_value, args)
commit cf02df084a6dbf85ef7f56a3ab177eac8975892c
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Mon Oct 26 23:45:42 2009 +0200

    Improve relevance ordering of search results.
    
    Weigh criteria descending based on order they're given in, and take
    into account the number of fields hit by each combination as well.

diff --git a/yum/__init__.py b/yum/__init__.py
index ff5e485..8b770cd 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1957,13 +1957,17 @@ class YumBase(depsolve.Depsolve):
         sorted_lists = {}
         tmpres = []
         real_crit = []
-        for s in criteria:
-            real_crit.append(s)
         real_crit_lower = [] # Take the s.lower()'s out of the loop
         rcl2c = {}
+        # weigh terms in given order (earlier = more relevant)
+        critweight = 0
+        critweights = {}
         for s in criteria:
+            real_crit.append(s)
             real_crit_lower.append(s.lower())
             rcl2c[s.lower()] = s
+            critweights.setdefault(s, critweight)
+            critweight -= 1
 
         for sack in self.pkgSack.sacks.values():
             tmpres.extend(sack.searchPrimaryFieldsMultipleStrings(sql_fields, real_crit))
@@ -1998,8 +2002,10 @@ class YumBase(depsolve.Depsolve):
         # By default just sort using package sorting
         sort_func = operator.itemgetter(0)
         if keys:
-            # Take into account the keys found, as well
-            sort_func = lambda x: "%s%s" % ("\0".join(sorted(x[1])), str(x[0]))
+            # Take into account the keys found, their original order,
+            # and number of fields hit as well
+            sort_func = lambda x: (-sum((critweights[y] for y in x[1])),
+                                   "\0".join(sorted(x[1])), -len(x[2]), x[0])
         yielded = {}
         for val in reversed(sorted(sorted_lists)):
             for (po, ks, vs) in sorted(sorted_lists[val], key=sort_func):


More information about the Yum-commits mailing list