[Django]-Search over multiple fields

9πŸ‘

βœ…

I guess thats because haystack uses the document field for generic searches unless you define a specific search for other fields like the twitter_account field.

from haystack documentation

Every SearchIndex requires there be
one (and only one) field with
document=True. This indicates to both
Haystack and the search engine about
which field is the primary field for
searching within.

Try specifing the index as follows

class UserProfileIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    user = CharField(model_attr='user')
    twitter_account = CharField(model_attr='twitter_account')

and create the a file named
search/indexes//userprofile_text.txt

which will contain the following

{{ object.user.get_full_name }}
{{ object.twitter_account}}

now haystack will search in the contents of this file (where you can add whatever you want) when you don’t specify an index filter.

πŸ‘€vinilios

Leave a comment