Django Haystack Index On Multiple Fields From Same Model
I am trying to embed elasticsearch in my Django app using django-haystack. I am trying to implement a user search. My user model is this: class MyUser(AbstractBaseUser): userna
Solution 1:
The way django-haystack works, the data inside the document=True
field is used for a general search, and any other fields are used for individual filtering. So in your case, a search will only use the name
field. To fix this, you'll need to use a template that specifies all the fields to be used in a search. First of all, use:
text = indexes.EdgeNgramField(document=True, use_template=True)
Then you’ll need to create a new template inside your template directory called search/indexes/myapp/myuser_text.txt
and place the following inside:
{{ object.username }}
{{ object.name }}
See http://django-haystack.readthedocs.org/en/latest/tutorial.html#handling-data for full reference
Post a Comment for "Django Haystack Index On Multiple Fields From Same Model"