def test_contact_search(self): contacts = self._create_contacts(10000, ["Bobby", "Jimmy", "Mary"]) self._create_values(contacts, self.field_nick, lambda c: c.name.lower().replace(' ', '_')) with SegmentProfiler("Contact search with simple query", self, force_profile=True): qs, is_complex = Contact.search(self.org, 'bob') self.assertEqual(3334, qs.count()) self.assertEqual(False, is_complex) with SegmentProfiler("Contact search with complex query", self, force_profile=True): qs, is_complex = Contact.search(self.org, 'name = bob or tel has 078 or twitter = tweep_123 or nick is bob') self.assertEqual(3377, qs.count()) self.assertEqual(True, is_complex)
def test_contact_search(self): contacts = self._create_contacts(10000, ["Bobby", "Jimmy", "Mary"]) self._create_values(contacts, self.field_nick, lambda c: c.name.lower().replace(' ', '_')) with SegmentProfiler(self, "Contact search with simple query", True): qs, is_complex = Contact.search(self.org, 'bob') self.assertEqual(3334, qs.count()) self.assertEqual(False, is_complex) with SegmentProfiler(self, "Contact search with complex query", True): qs, is_complex = Contact.search(self.org, 'name = bob or tel has 078 or twitter = tweep_123 or nick is bob') self.assertEqual(3377, qs.count()) self.assertEqual(True, is_complex)
def get_queryset(self, **kwargs): qs = super(ContactListView, self).get_queryset(**kwargs) org = self.request.user.get_org() # contact list views don't use regular field searching but use more complex contact searching query = self.request.REQUEST.get('search', None) if query: qs, self.request.compiled_query = Contact.search(org, query, qs) return qs.prefetch_related('groups')
def get_queryset(self, **kwargs): qs = super(ContactListView, self).get_queryset(**kwargs) qs = qs.filter(is_test=False) org = self.request.user.get_org() # contact list views don't use regular field searching but use more complex contact searching query = self.request.REQUEST.get('search', None) if query: qs, self.request.compiled_query = Contact.search(org, query, qs) return qs.extra(select={'lower_contact_name': 'lower(contacts_contact.name)'}).order_by('lower_contact_name', 'pk').prefetch_related('all_groups')