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
我正在使用django-haystack。我编写了一些小代码,用于从UserProfile中搜索州和国家。如果我搜索州/国家,那么它就像魅力一样。但是,如果我搜索用户,那么它不会显示任何结果。我错过了什么吗?谢谢
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'),
)
2 个解决方案
#1
1
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.
在数据模板(UserProfile_text文件)中。从索引中搜索数据模板中定义的内容。
#2
0
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. Return a u"..."
String instead.
另请注意,一旦您的名称中包含非ASCII符号的用户,您的repare_author(self,obj)就会中断。返回一个u“...”字符串。
#1
1
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.
在数据模板(UserProfile_text文件)中。从索引中搜索数据模板中定义的内容。
#2
0
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. Return a u"..."
String instead.
另请注意,一旦您的名称中包含非ASCII符号的用户,您的repare_author(self,obj)就会中断。返回一个u“...”字符串。