I am setting up django-haystack and just have a question.
I use django-profiles, which allows me to add seperate information ie, city, gender etc.
I created a search_indexes.py
for my UserProfile
when I perform a search it only seems to return a users username result ie.
if I type john
and the users username is john then it gets picked up, if I type James
and the user john
's first name is James
it does not return a result.
my search_indexes.py
from haystack.indexes import *
from haystack import site
from models import UserProfile
class UserProfileIndex(SearchIndex):
text = CharFie开发者_高级运维ld(document=True, use_template=True)
user = CharField(model_attr='user', use_template=True)
def prepare_user(self, obj):
return "%s <%s>" % (obj.user.get_full_name(), obj.user.email)
site.register(UserProfile, UserProfileIndex)
I've only glanced over haystack code before, but isn't it because you're indexing on the model attribute "user" which means that will be the only field searched?
What is the content of your UserProfile_text.txt (the SearchIndex template)? It should be something like
{{ object.username }}
{{ object.firstname }}
...
with all the fields you want indexed from that model. See the documentation
the key point is
basicly you define what keywords you wantted to be indexed in your template of your index model
so please add fields that you need into your template file
The template file should be like:
{{ object.user.first_name}}
{{ object.user.middle_name }}
精彩评论