facet error

8 views
Skip to first unread message

@@

unread,
Nov 26, 2009, 10:24:29 AM11/26/09
to django-...@googlegroups.com
Hi,
I'm trying facet, but got an error. 

'set' object has no attribute 'append'
/project_path/haystack/backends/xapian_backend.py in search
        if limit_to_registered_models:
            if narrow_queries is None:
                 narrow_queries = []
            registered_models = self.build_registered_models_list()
            if len(registered_models) > 0:
                narrow_queries.append( ...
                    ' '.join(['django_ct:%s' % model for model in registered_models])
                )
        database = self._database()
        query, spelling_suggestion = self._query(
            database, query_string, narrow_queries, spelling_query, boost

the narrow_queries is a set.
 'narrow_queries': set([u'category:\u65c5\u6e38'])

Is this a problem of haystack's or xapian backends?

@@

unread,
Nov 26, 2009, 10:36:27 AM11/26/09
to django-...@googlegroups.com
It seems that haystack use set() to store narrow_queries. But xapian backend use [] to store narrow_queries.
So i guess xapian backend has to use set() as well?

David Sauve

unread,
Nov 26, 2009, 4:22:32 PM11/26/09
to django-...@googlegroups.com
Ah hah!  It seems this was changed in SHA 96d51e825b0621de6aa6fccfa6b5cdfde3d6b3d8 and I didn't notice.  No worries though, I just committed a fix for it.  Thanks for catching and reporting this.

David

--

You received this message because you are subscribed to the Google Groups "django-haystack" group.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.

@@

unread,
Nov 26, 2009, 11:31:26 PM11/26/09
to django-...@googlegroups.com
Thanks :)
But i notice that there is another place use list instead of set.
xapian-haystack / xapian_backend.py about line 455


                narrow_queries = []
                narrow_queries.append(

PatrickB

unread,
Nov 26, 2009, 4:26:05 PM11/26/09
to django-haystack
This appears to be a bug in the Xapian backend. But, there seems to be
a very easy solution.
Open the xapian_backend.py file, go to line 337, where you will find
this:
if len(registered_models) > 0:
narrow_queries.append(
' '.join(['django_ct:%s' % model for model in
registered_models])
)
This doesn't work, but if you simply change the .append to .add, it
still won't work. The solution is to do both methods, like this:
if len(registered_models) > 0:
try:
narrow_queries.append(
' '.join(['django_ct:%s' % model for model in
registered_models])
)
except AttributeError:
narrow_queries.add(
' '.join(['django_ct:%s' % model for model in
registered_models])
)

This fixes it for me, and faceting is working (more or less... some
problems with ForeignKeys). As always with Python, note the
indenting.

I have fixed this quickly in the train this morning, and this is
provided on an as-is basis. There is absolutely no warranty.

David Sauve

unread,
Nov 27, 2009, 12:40:34 PM11/27/09
to django-...@googlegroups.com
I've pushed a fix for this to Github.  Can you confirm it's working as expected?

@@

unread,
Nov 28, 2009, 11:11:48 AM11/28/09
to django-...@googlegroups.com
Hi, i changed my code myself the way as you did earlier.
It works so far in my test :)
Thanks

David Sauve

unread,
Nov 28, 2009, 11:21:09 AM11/28/09
to django-...@googlegroups.com
Great, glad it's working.  I'm hoping to actually get some time in the next few weeks to done some more work on the xaian_backend and close off some long standing issues.  Appreciate the bug submissions and tracebacks.
Reply all
Reply to author
Forward
0 new messages