[kupfer] relevance: _findBestMatch must take first best match
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] relevance: _findBestMatch must take first best match
- Date: Sun, 13 Sep 2009 01:11:22 +0000 (UTC)
commit 9744979115280d5fd2d3ee41305253612151b469
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sat Sep 12 22:58:10 2009 +0200
relevance: _findBestMatch must take first best match
If a match is perfect, it can not get better. we take the first
perfect match; we only update best match if it's better.
kupfer/relevance.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/relevance.py b/kupfer/relevance.py
index 6088f01..6fc17f1 100644
--- a/kupfer/relevance.py
+++ b/kupfer/relevance.py
@@ -216,7 +216,13 @@ def _findBestMatch(s, query):
return bestMatch
cur += 1
qcur += 1
- bestMatch = (index, cur)
+
+ # take match if it is shorter
+ # if perfect match, we are done
+ if bestMatch[0] == -1 or (cur - index) < (bestMatch[1] - bestMatch[0]):
+ bestMatch = (index, cur)
+ if cur - index == queryLength:
+ break
index = s.find(query[0], index + 1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]