[kupfer] relevance: Simplify unecessary conditionals



commit d55289e0bdae47dadbc7b6b9d92e199dc72d664a
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Sep 16 06:46:59 2009 +0200

    relevance: Simplify unecessary conditionals
    
    One conditional asks for 'last == len(query) -1', which can never be
    true since last >= len(query). Instead of fixing the branch, we remove
    this condition; it was never used and our rankings are good enough.
    
    Also final score update is guarded by if good + bad > 0:; but we never
    decrement either and the sum starts at 1 so it is always true.
    
    Remove unnecessary score = 0.0

 kupfer/relevance.py |   20 +++++++-------------
 1 files changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/kupfer/relevance.py b/kupfer/relevance.py
index 22c19e2..1f3e2d2 100644
--- a/kupfer/relevance.py
+++ b/kupfer/relevance.py
@@ -112,10 +112,9 @@ def score(s, query):
     """
     if not query:
         return 1.0
-    
-    score = 0.0
+
     ls = s.lower()
-    
+
     # Find the shortest possible substring that matches the query
     # and get the ration of their lengths for a base score
     first, last = _findBestMatch(ls, query)
@@ -148,19 +147,14 @@ def score(s, query):
     # Better yet if the match itself started there
     if first == 0:
         good += 2
-        
-    # Super bonus if the whole match is at the beginning
-    if last == len(query) - 1:
-        good += last + 4
-        
+
     # Super duper bonus if it is a perfect match
     if query == ls:
         good += last * 2 + 4
-        
-    if good + bad > 0:
-        score = (score + 3 * good / (good + bad)) / 4
-        
-    # This fix makes sure tha tperfect matches always rank higher
+
+    score = (score + 3 * good / (good + bad)) / 4
+
+    # This fix makes sure that perfect matches always rank higher
     # than split matches.  Perfect matches get the .9 - 1.0 range
     # everything else lower
     



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]