简体   繁体   中英

Trying to perform an index search for user's (django-haystack)

I'm using django-haystack . I've written small code which search the state and country from UserProfile . If i search state/country then It works like charm. But if I search the user then it does not showing any result. Am I missing something? thanks

class UserProfileIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    author = indexes.CharField(model_attr='user', faceted=True)
    state = indexes.CharField(model_attr='state') 
    country = indexes.CharField(model_attr='country', null=True) 


def get_model(self):
    return UserProfile

def index_queryset(self):
    return self.get_model().objects.all()

def prepare_author(self, obj):
    return "%s <%s>" % (obj.user.get_full_name(), obj.user.email)

Here url

sqs = SearchQuerySet().facet('author')      
urlpatterns += patterns('haystack.views',
    url(r'^search/', FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs), name='haystack_search'),
)

what is content of your data template have you included something like

{{object.user}} 

in data template (UserProfile_text file ). What ever is defined in data template is searched from the index.

How's your UserProfile defined?

Also note that your repare_author(self, obj) will break once you have users with non-ASCII symbols in their names. Return a u"..." String instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM