使用 ResultSet 访问实际对象 从 Djapian 上的索引搜索返回命中对象
我希望能够在查询时返回实际的对象列表,而不是带有 Hit 对象的 ResultSet。
示例:
indexer.search(word).prefetch()
这将返回一个具有匹配命中的 ResultSet 对象,但我希望能够访问这些对象本身。类似于:
model.objects.filter(name__icontains=word)
会返回。 我不只使用第二个选项的原因是我无法搜索不同模型的交叉对象,这可以通过索引来完成。
谢谢
I want to be able to have an actual list of objects returned when I query, instead of a ResultSet with Hit objects.
Example:
indexer.search(word).prefetch()
this would return a ResultSet object with matching hits, but I would like to have access to the objects themselves. Similar to what:
model.objects.filter(name__icontains=word)
would return.
the reason I don't just use the second option is that I cannot search cross-objects of different models, which can be done with indexing.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。对象最终被返回。可以通过以下方式访问它:
其中 model_attribute 是返回对象的现有变量
我相信类函数也可以在 model_attribute 位置调用(最后添加括号),
但请注意搜索跨模型时,不同模型可能存在或不存在“
model_attribute
”。所以这可能会导致错误。我希望 djapian 有更多关于此的文档,因为我根本找不到它
I figured it out. The object is returned afterall. It can be accessed with:
where
model_attribute
would be an existing variable of the object returnedI believe class functions can be called upon as well in the model_attribute spot, (with bracket added in the end)
but note that when searching cross-models, the '
model_attribute
' may or may not exist for different models. So that may lead to errors.I wish djapian had more documentation on this, as I couldn't find it at all