【发布时间】:2015-03-07 15:36:31
【问题描述】:
我正在使用 Django 构建问答解决方案 答案模型有外键提问
在实现搜索时,我希望它像 quora 的默认搜索一样,其中搜索到的查询既可以在问题中找到,也可以在问题的任何答案中出现,它会显示在问题下方。
那么基本上我该如何构建搜索索引模板呢?
如果我创建一个包含所有答案正文的文档模板
class QuestionIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
created_at = indexes.DateTimeField(model_attr='created_at')
def get_model(self):
return Question
问题文档模板为
{{ object.title }}
{{ object.body }}
{% for answer in object.answers %}
{{answer.body}}
{% endfor %}
在视图中如何获取找到匹配项的特定答案对象?
或者我应该为答案创建单独的索引?
【问题讨论】: