python - django-sphinx BuildExcerpts -
i'm trying use buildexcerpts in django sphinx. view looks 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 run assertionerror
here's 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 @ / exception value:
i'm not sure what's going on. have experience this?
i'm using django 1.2.3, sphinx 0.9.9, , django-sphinx 2.2.3.
for others having similar problems, here had fix it.
go django-sphinx install folder , open models.py. on line 650, need replace these 2 lines:
docs = [getattr(instance, f) f in fields] if isinstance(self._passages_opts, dict):
with
docs = [getattr(instance, f) f in fields] index, doc in enumerate(docs): if (not (isinstance(doc, str)) , (not isinstance(doc, unicode))): docs[index] = repr(doc) if isinstance(self._passages_opts, dict):
then can access excerpts in view:
for r in results_set: print r.sphinx.get('passages')
or in template this:
{{record.sphinx.passages.content|safe}}
Comments
Post a Comment