django-sphinx 构建摘录

发布于 2024-10-05 03:24:16 字数 1878 浏览 1 评论 0原文

我正在尝试在 django sphinx 中使用 BuildExcerpts。我的视图看起来像这样:

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

这是跟踪:

Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\myproject\myapp\views.py" in home_page
  81.             my_model_list = remove_duplicates(list(my_model_list))
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in __iter__
  243.         return iter(self._get_data())
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_data
  422.             self._result_cache = list(self._get_results())
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_results
  603.                             r['passages'] = self._get_passages(queryset[r['id']], results['fields'], words)
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_passages
  657.         passages_list = client.BuildExcerpts(docs, self._index, words, opts)
File "C:\Python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\apis\api278\__init__.py" in BuildExcerpts
  791.          assert(isinstance(doc, str))

Exception Type: AssertionError at /
Exception Value: 

我不太确定发生了什么。有人有这方面的经验吗?

我正在使用 django 1.2.3、Sphinx 0.9.9 和 django-sphinx 2.2.3。

I'm trying to use BuildExcerpts in django sphinx. My view looks something like this:

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,
                         })

When I run this I get an AssertionError

Here's the trace:

Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\myproject\myapp\views.py" in home_page
  81.             my_model_list = remove_duplicates(list(my_model_list))
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in __iter__
  243.         return iter(self._get_data())
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_data
  422.             self._result_cache = list(self._get_results())
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_results
  603.                             r['passages'] = self._get_passages(queryset[r['id']], results['fields'], words)
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\models.py" in _get_passages
  657.         passages_list = client.BuildExcerpts(docs, self._index, words, opts)
File "C:\Python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\apis\api278\__init__.py" in BuildExcerpts
  791.          assert(isinstance(doc, str))

Exception Type: AssertionError at /
Exception Value: 

I'm not really sure what's going on. Anyone have an experience with this?

I'm using django 1.2.3, Sphinx 0.9.9, and django-sphinx 2.2.3.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2024-10-12 03:24:16

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

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

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

 docs = [getattr(instance, f) for f in fields]

 for index, doc in enumerate(docs):
     if (not (isinstance(doc, str)) and (not isinstance(doc, unicode))):
                         docs[index] = repr(doc)

  if isinstance(self._passages_opts, dict):

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

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

或在模板中像这样:

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

For others who are having similar problems, here is what I had to do to fix it.

Go to your django-sphinx install folder and open up models.py. On line 650, you need to replace these two lines:

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

with

 docs = [getattr(instance, f) for f in fields]

 for index, doc in enumerate(docs):
     if (not (isinstance(doc, str)) and (not isinstance(doc, unicode))):
                         docs[index] = repr(doc)

  if isinstance(self._passages_opts, dict):

Then you can access your excerpts like this in your view:

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

or in the template like this:

{{record.sphinx.passages.content|safe}} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文