From 72473c0c4897fa8b62d19005b7fc19bdb459f8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 7 Dec 2011 11:07:39 +0100 Subject: [PATCH] always use text index for contact lookup --- themis/search/contact-input.pt | 20 ++------------------ themis/search/indexer.py | 17 +++++------------ themis/search/mail.pt | 18 ++++++++++++++++++ themis/search/mail.py | 14 ++------------ 4 files changed, 27 insertions(+), 42 deletions(-) diff --git a/themis/search/contact-input.pt b/themis/search/contact-input.pt index c98a715..9459e69 100644 --- a/themis/search/contact-input.pt +++ b/themis/search/contact-input.pt @@ -2,38 +2,22 @@ xmlns:tal="http://xml.zope.org/namespaces/tal" tal:omit-tag="">
- diff --git a/themis/search/indexer.py b/themis/search/indexer.py index 6845ade..89bf7e7 100644 --- a/themis/search/indexer.py +++ b/themis/search/indexer.py @@ -59,7 +59,6 @@ def mail_dynamic_searchable_text_indexer(obj): grok.global_adapter(mail_dynamic_searchable_text_indexer, name='MailSearchableText') - @indexer(plone.dexterity.interfaces.IDexterityItem) def contactIndexer(obj): if obj.portal_type not in ('courrier_entrant', 'courrier_sortant'): @@ -72,16 +71,7 @@ def contactIndexer(obj): if not v: continue v = v[0] - if ':' in v and v.split(':')[0] in ('deputy', 'ministry', 'ministry-collab'): - return v - elif ':' in v and v.split(':')[0] == 'contact': - contact_id = v.split(':')[1] - if not hasattr(contacts_dir, contact_id): - return contact_id.replace('-', ' ') - else: - return getattr(contacts_dir, contact_id).title - else: - return v + return v return None grok.global_adapter(contactIndexer, name="MailContact") @@ -99,7 +89,10 @@ def contactFuzzyIndexer(obj): v = v[0] if ':' in v: src = ContactsSource() - return src(obj).getTermByToken(v).title + r = src.fastGetTitleByToken(obj, v) + if not type(r) is unicode: + r = unicode(r, 'utf-8') + return r else: return v return None diff --git a/themis/search/mail.pt b/themis/search/mail.pt index 16e029d..ffa05df 100644 --- a/themis/search/mail.pt +++ b/themis/search/mail.pt @@ -61,6 +61,24 @@ td.date {
+ + diff --git a/themis/search/mail.py b/themis/search/mail.py index ac62d77..fdc7b65 100644 --- a/themis/search/mail.py +++ b/themis/search/mail.py @@ -31,15 +31,9 @@ class ContactWidget(TextWidget): return self.input_template(self) return TextWidget.render(self) - def extract(self, default=z3c.form.interfaces.NO_VALUE): - t = self.request.get(self.name, default) - if not t: - t = self.request.get(self.name + '-select', default) - return t - def get_known_contacts(self): terms = get_terms_for_persons(self.context, include_deputies=True, - include_ministries=True, include_ministries_collaborators=True) + include_ministries=True) return terms @@ -117,11 +111,7 @@ class SearchView(BrowserView): if data.get('subcategory'): kw['sous_categorie_de_courrier'] = data.get('subcategory') if data.get('contact'): - v = data.get('contact') - if ':' in v and v.split(':')[0] in ('deputy', 'ministry', 'ministry-collab'): - kw['MailContact'] = v - else: - kw['MailContactFuzzy'] = v + kw['MailContactFuzzy'] = data.get('contact') if data.get('scope') == 'all': kw['portal_type'] = ['courrier_entrant', 'courrier_sortant']