Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:59:40+00:00 2026-05-14T16:59:40+00:00

I think I don’t unterstand django-haystack properly: I have a data model containing several

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:59:41+00:00Added an answer on May 14, 2026 at 4:59 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't think this can be done cleanly, but I'll ask anyway. I have
I would like to do the following but I don't think this will work:
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't think this is possible, but if is then I need it :)
I don't think that this is specific to a language or framework, but I
I don't think this is possible, but I'll ask anyway... Is there some way
This is an accident and I don't think there's a solution. But I'm asking
I'm a bit new to WCF and I don't think I completely understand what
Based on a simple test I ran, I don't think it's possible to put
I'm seeing an ambiguous error in Firebug. I don't think it's particularly related to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.