django-sphinx BuildExcerpts

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

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

my_model_list =, passages_opts={
                        'before_match':"<font color='red'>",
                        'chunk_separator':' ... ',

When I run this I get an AssertionError

Here's the trace:

File "C:\Python25\lib\site-packages\django\core\handlers\" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\myproject\myapp\" 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\" in __iter__
  243.         return iter(self._get_data())
File "c:\python25\lib\site-packages\django_sphinx-2.2.3-py2.5.egg\djangosphinx\" 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\" 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\" 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\" 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.


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 On line 650, you need to replace these two lines:

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):

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:


Need Your Help

Get numeric part from string using regex and c#

c# regex

Anyone keen to show me how to get the integer part from this string using c#?

how to make a searchable String ID with a byte using java and hibernate

java mysql hibernate java-ee rfid

i am working on a RFID project, in which i should identify vehicles with their RFID tag.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.