[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819
Sebastian Krzyszkowiak
seba.dos1 at gmail.com
Sat Aug 6 08:17:32 UTC 2011
The following commit has been merged in the debian branch:
commit 68f24bc3db6539db192f5f416ea5ca117f1af7de
Author: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
Date: Sat Jul 25 14:48:48 2009 +0200
Use regular expressions instead of difflib in Contacts domain
Signed-off-by: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
diff --git a/framework/subsystems/opimd/pimd_contacts.py b/framework/subsystems/opimd/pimd_contacts.py
index a07de85..fb24673 100644
--- a/framework/subsystems/opimd/pimd_contacts.py
+++ b/framework/subsystems/opimd/pimd_contacts.py
@@ -21,7 +21,7 @@ from dbus.service import method as dbus_method
import logging
logger = logging.getLogger('opimd')
-from difflib import SequenceMatcher
+import re
from backend_manager import BackendManager
from backend_manager import PIMB_CAN_ADD_ENTRY, PIMB_CAN_DEL_ENTRY, PIMB_CAN_UPD_ENTRY, PIMB_CAN_UPD_ENTRY_WITH_NEW_FIELD, PIMB_NEEDS_SYNC
@@ -36,8 +36,6 @@ from framework.config import config, busmap
_DOMAIN_NAME = "Contacts"
-_MIN_MATCH_TRESHOLD = 0.69
-
_DBUS_PATH_CONTACTS = DBUS_PATH_BASE_FSO + '/' + _DOMAIN_NAME
_DIN_CONTACTS_BASE = DIN_BASE_FSO
@@ -75,13 +73,13 @@ class ContactQueryMatcher(object):
for (contact_id, contact) in enumerate(contacts):
if contact:
match = contact.match_query(self.query_obj)
- if match > _MIN_MATCH_TRESHOLD:
+ if match > 0.0:
matches.append((match, contact_id))
result_count = len(matches)
# Sort matches by relevance and return the best hits
if result_count > 0:
- matches.sort()
+ matches.sort(reverse = True)
limit = result_count
if self.query_obj.has_key("_limit"):
@@ -361,7 +359,6 @@ class Contact():
@return Accuracy of the match, ranging from 0.0 (no match) to 1.0 (complete match)"""
overall_match = 1.0
- matcher = SequenceMatcher()
for field_name in query_obj.keys():
# Skip fields only meaningful to the parser
@@ -370,8 +367,7 @@ class Contact():
field_value = str(query_obj[field_name])
best_field_match = 0.0
- # The matcher internally caches details about seq2, so let's make use of that
- matcher.set_seq2(field_value)
+ matcher = re.compile(field_value)
seq2_len = len(field_value)
# Check if field value(s) of this contact match(es) the query field
@@ -387,13 +383,16 @@ class Contact():
comp_value = str(self._fields[field_id][1])
# Compare and determine the best match ratio
- matcher.set_seq1(comp_value)
- match = matcher.find_longest_match(0, len(comp_value), 0, seq2_len)
- match_len = match[2]
+ match = matcher.search(comp_value)
+ if match:
+ match_len = match.end() - match.start()
+ else:
+ match_len = 0
+
if seq2_len==0:
field_match = 0.0
else:
- field_match = float(match_len) / seq2_len
+ field_match = float(match_len) / len(comp_value)
if field_match > best_field_match: best_field_match = field_match
logger.debug("Contacts: Field match for %s / %s: %f", comp_value, field_value, field_match)
@@ -408,7 +407,7 @@ class Contact():
overall_match *= best_field_match
# Stop comparing if there is too little similarity
- if overall_match < _MIN_MATCH_TRESHOLD: break
+ if overall_match == 0.0: break
return overall_match
--
FSO frameworkd Debian packaging
More information about the pkg-fso-commits
mailing list