I think that should fix it:
https://github.com/discourse/discourse/pull/7977
The issue we had is that to prevent some error we had this HAVING #{disagreed} > #{agreed}
clause which is essentially preventing a lot of results to show.
if you have 5 disagreed and 20 agreed, you wouldn’t show in results. This fix also bumps people with 0 disagreed flags, their score will be agreed^2.