Django - Haystack 查询序列化
我正在尝试序列化 HayStack SearchQuerySet
:
from django.core import serializers
serializers.serialize("json", SearchQuerySet().filter(content=request.GET['q']))
但它会抛出:
“SearchQuery”对象没有属性“_build_query”
我该如何解决这个问题?
I'm trying to serialize a HayStack SearchQuerySet
:
from django.core import serializers
serializers.serialize("json", SearchQuerySet().filter(content=request.GET['q']))
but it throws:
'SearchQuery' object has no attribute '_build_query'
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不建议为每个结果调用“对象”,因为它会影响数据库并超出搜索性能的目的。相反,请考虑调用可与 json 转储一起使用的 get_stored_fields 方法:
I don't recommend call 'object' per result as it would hit to database and beat purpose of search performance. Instead consider calling get_stored_fields method which can be used with json dumps:
我也遇到过类似的问题。
使用类似的东西并且它有效:
serializers.serialize("json", [x.object for x in queryset]
I had faced a similar problem.
used something like this and it worked:
serializers.serialize("json", [x.object for x in queryset]