8

Returning search results ordered by upvotes (or downvotes), possible?

To clarify the difference between ordering by score, if I were searching for most downvoted posts I would want a question on +2 (+6 / -4) to appear in the results before some other questions on +1 (+3/-2) and +3 (+3/-0) because the +2 scored post has the most downvotes.

Options using SEDE acceptable.

6
  • Why do you need this?
    – dWinder
    Commented Aug 5, 2019 at 21:09
  • 3
    I want to search most upvoted/downvoted posts irrespective of their net score.
    – wim
    Commented Aug 5, 2019 at 21:09
  • 4
    On main sites I want to find posts that were downvoted a lot, so that they can be improved. On meta sites I want to be able to find posts that are controversial topics (high upvote and downvote scores, with a "quiet" net score)
    – wim
    Commented Aug 5, 2019 at 21:10
  • So why total score not enough? If some user up-vote the post it mean it is not that bad - look of most negative score post and improve them
    – dWinder
    Commented Aug 5, 2019 at 21:12
  • 2
    Because total score ~0 does not sufficiently distinguish between "meh", or "low views". And on main I already delete all my stuff with negative score, so there aren't many of those left to improve.
    – wim
    Commented Aug 5, 2019 at 21:13
  • 2
    And I think your claim is wrong, there are plenty of up-voted posts that are also just bad (e.g. they used to be good but became obsolete or deprecated)!
    – wim
    Commented Aug 5, 2019 at 21:15

1 Answer 1

5

This query list the up and downvotes per post

Input 0 for the userid to get the votes for all posts or enter an userid.

select top 1000
       postid as [Post Link]
     , sum(case when votetypeid = 2 then 1 else 0 end) upvotes
     , sum(case when votetypeid = 3 then 1 else 0 end) downvotes
     , min(p.score) score
from votes v
inner join posts p on p.id = v.postid
where votetypeid in (2, 3) -- upmod, downmod
and posttypeid in (1, 2) -- Q, A
and ('##userid?674039##' = 0 or owneruserid = ##userid?674039##)
group by postid
order by (select max(val) 
          from ( select sum(case when votetypeid = 2 then 1 else 0 end) val
                union
                select sum(case when votetypeid = 3 then 1 else 0 end)
          ) alldata
         ) desc

When run today this is your result:

enter image description here

5
  • It looks like deleted posts don't link in the "Post Link" instead just a row with ids plaintext like 252534 and 250033
    – wim
    Commented Aug 9, 2019 at 14:50
  • @wim that is correct. That is partly due to the fact that the title column is sanitized for deleted posts and partly due to the fact that the internal SEDE query that creates that link is looking at the Posts table, not at PostsWithDeleted. In cases where this is really relevant I tend to use the feature in SEDE to build my own link (basically generate a site://q/{id}|link title string) but that is not done here.
    – rene
    Commented Aug 9, 2019 at 15:24
  • Can you please add a filter parameter on post.owneruserid=##userid## and an additional column for the post score?
    – wim
    Commented Aug 9, 2019 at 15:27
  • @wim that is now done.
    – rene
    Commented Aug 9, 2019 at 15:47
  • Very good - thank you rene!
    – wim
    Commented Aug 9, 2019 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .