Using the django-haystack and solr as a search engine, I have successfully implemented a search engine which throws out the list of users whose usernames, first names, last names, or email addresses match the given query.
search_indexes.py
from haystack.indexes import *
from haystack import site
from django.contrib.auth.models import User
class UserIndex(SearchIndex):
text = CharField(document=True, use_template=True)
first_name = CharField(model_attr='first_name')
last_name = CharField(model_attr='last_name')
email = CharField(model_attr='email')
def index_queryset(self):
return User.objects.exclude(username='root')
site.register(User, UserIndex)
and
user_text.txt
{{ object.username }}
{{ object.first_name }}
{{ object.last_name }}
{{ object.email }}
However, I am planning to let the users set their privacy settings so that they will not be searchable with their first_name, last_name, or email address.
I have been banging my head and my computer for days trying to accomplish this functionality but haven’t found any real good solution yet.
Is it at all possible to accomplish the above functionality?
Thank you very much in advance.
You can create a constraints table and e.g. use haystack’s SearchQuerySet to exclude upon. Here’s an example using tastypie as an API, but this might as well be your custom service or view layer.
http://django-tastypie.readthedocs.org/en/latest/resources.html#advanced-filtering