'Search on the ES index the query sting provided by the user.'

def search(self):

    search_term = self.cleaned_data.get('q')
    profile = None
    location_query = {}
    if self.country:
        location_query['country'] = self.country
        location_query['privacy_country__gte'] = None
    if self.region:
        location_query['region'] = self.region
        location_query['privacy_region__gte'] = None
    if self.city:
        location_query['city'] = self.city
        location_query['privacy_city__gte'] = None
    try:
        profile = self.request.user.userprofile
    except AttributeError:
        privacy_level = PUBLIC
    else:
        privacy_level = profile.privacy_level
    if (profile and profile.is_vouched):
        search_models = self.get_models()
    else:
        search_models = [UserProfile]
    if location_query:
        for k in location_query.keys():
            if k.startswith('privacy_'):
                location_query[k] = privacy_level
        return (SearchQuerySet().filter(**location_query).load_all() or self.no_query_found())
    sqs = super(PhonebookSearchForm, self).search().models(*search_models)
    if (not sqs):
        return self.no_query_found()
    query = SQ()
    q_args = {}
    all_indexed_fields = UserProfileIndex.fields.keys()
    privacy_indexed_fields = [field for field in all_indexed_fields if field.startswith('privacy_')]
    for p_field in privacy_indexed_fields:
        q_field = p_field.split('_', 1)[1]
        q_args = {q_field: search_term, '{0}__gte'.format(p_field): privacy_level}
        query.add(SQ(**q_args), SQ.OR)
    query.add(SQ(**{'username': search_term}), SQ.OR)
    if ((not search_models) or (Group in search_models)):
        query.add(SQ(**{'visible': True}), SQ.OR)
    return sqs.filter(query).load_all()
