Very odd behaviour when merging multiple SearchQuerySets with the pipe operator

45 views
Skip to first unread message

Salvatore Iovene

unread,
Nov 9, 2017, 1:00:34 PM11/9/17
to django-haystack
Hi,
I have multiple search index, and a complex search form. According to the user selection in the search form, I apply filters to my search indexes.

At the end, I merge the results with the pipe operator.

I found that I can make a search that results in empty results in each individual SearchQuerySet for each individual search index, but when I merge them, the result is the complete set of my indexed objects.

Easy to see it in the following pdb session:

> /var/www/astrobin/astrobin/forms.py(567)search()
-> print "len(sqs) = %d" % len(sqs)
(Pdb)
len(sqs) = 0
> /var/www/astrobin/astrobin/forms.py(568)search()
-> print "len(user_sqs) = %d" % len(user_sqs)
(Pdb)
len(user_sqs) = 0
> /var/www/astrobin/astrobin/forms.py(569)search()
-> print "len(image_sqs) = %d" % len(user_sqs)
(Pdb)
len(image_sqs) = 0
> /var/www/astrobin/astrobin/forms.py(570)search()
-> print "len(gear_sqs) = %d" % len(user_sqs)
(Pdb)
len(gear_sqs) = 0
> /var/www/astrobin/astrobin/forms.py(572)search()
-> sqs = sqs | user_sqs | image_sqs | gear_sqs
(Pdb)
> /var/www/astrobin/astrobin/forms.py(573)search()
-> print "len(sqs) = %d" % len(sqs)
(Pdb)
len(sqs) = 1

(where 1 is the total number of objects in my Image search index.

So, why did merging the querysets return an object when all of them had no results?

Am I doing something wrong?

I run django-haystack 2.6.1.

Thanks!
Salvatore
Reply all
Reply to author
Forward
0 new messages