简体   繁体   English

尝试对用户的 (django-haystack) 执行索引搜索

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

I'm using django-haystack .我正在使用django-haystack I've written small code which search the state and country from UserProfile .我编写了从UserProfile搜索 state 和国家/地区的小代码。 If i search state/country then It works like charm.如果我搜索州/国家,那么它就像魅力一样。 But if I search the user then it does not showing any result.但是,如果我搜索user ,则不会显示任何结果。 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这里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 ).在数据模板(UserProfile_text 文件)中。 What ever is defined in data template is searched from the index.从索引中搜索数据模板中定义的内容。

How's your UserProfile defined?您的UserProfile是如何定义的?

Also note that your repare_author(self, obj) will break once you have users with non-ASCII symbols in their names.另请注意,一旦您的用户名称中包含非 ASCII 符号,您的repare_author(self, obj)就会中断。 Return a u"..." String instead.返回一个u"..."字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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