The query returns the right records without duplicates (there's even a DISTINCT in the query), but the annotations compute the wrong answers. I'm not SQL expert enough to understand exactly what's wrong with the query, but this sounds like https://code.djangoproject.com/ticket/10060. That's been open for 5 years. I guess it's a hard problem :-)

I'm not sure how we would fix this particular problem outside the admin, since the admin is applying the multiple joins due to the search fields crossing multiple tables, and we have to do the fix after that.

The ``set`` in my fix is redundant for multiple reasons and could be removed.