Djangosphinx构建摘要

2024-06-25 22:56:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在django sphinx中使用buildextracts。我的观点是这样的:

q = request.GET.get('q', '')

my_model_list = MyModel.search.query(q).set_options(passages=True, passages_opts={
                        'before_match':"<font color='red'>",
                        'after_match':'</font>',
                        'chunk_separator':' ... ',
                        'around':6,
                         })

当我运行这个时,我得到一个AssertionError

以下是线索:

^{pr2}$

我不太清楚发生了什么事。有人有过这样的经历吗?在

我使用的是django 1.2.3、sphinx0.9.9和django-sphinx2.2.3。在


Tags: djangosearchgetmodelrequestmymatchsphinx
1条回答
网友
1楼 · 发布于 2024-06-25 22:56:09

对于其他有类似问题的人,这里是我必须做的来解决它。在

转到django sphinx安装文件夹并打开模型.py. 在第650行,您需要替换这两行:

docs = [getattr(instance, f) for f in fields]
if isinstance(self._passages_opts, dict):

^{pr2}$

然后您可以在您的视图中访问摘录:

for r in results_set:
   print r.sphinx.get('passages') 

或者在这样的模板中:

{{record.sphinx.passages.content|safe}} 

相关问题 更多 >