Search over multiple fields

Posted by schneck on Stack Overflow See other posts from Stack Overflow or by schneck
Published on 2010-04-28T20:29:12Z Indexed on 2010/04/30 1:27 UTC
Read the original article Hit count: 351

Filed under:
|

Hi there,

I think I don't unterstand django-haystack properly:

I have a data model containing several fields, and I would to have two of them searched:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True, default=None)
    twitter_account = models.CharField(max_length=50, blank=False)

My search index settings:

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

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return UserProfile.objects.all()

But when I perform a search, only the field "username" is searched; "twitter_account" is ignored. When I select the Searchresults via dbshell, the objects contain the correct values for "user" and "twitter_account", but the result page shows a "no results":

    {% if query %}
        <h3>Results</h3>

        {% for result in page.object_list %}
            <p>
               <a href="{{ result.object.get_absolute_url }}">{{ result.object.id }}</a>
            </p>
        {% empty %}
            <p>No results</p>
        {% endfor %}
    {% endif %}

Any ideas?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-haystack