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を使用しています。

4

1 に答える 1

1

同様の問題を抱えている他の人のために、これを修正するために私がしなければならなかったことを次に示します。

django-sphinx インストール フォルダーに移動し、models.py を開きます。650 行目で、次の 2 行を置き換える必要があります。

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}} 
于 2011-03-03T00:37:00.463 に答える