1

Looking at this stackoverflow question:

https://stackoverflow.com/questions/3012488?tab=votes#tab-top

when sort is by votes, the accepted_answer is always on top regardless of answer's upvotes.

Calling questions/id/answers with sort=votes does not give the same result.
Here an example:

http://api.cooking.stackexchange.com/1.0/questions/567/answers?sort=votes&body=true

or, for a formatted view:

http://stackprinter.appspot.com/export?question=567&format=HTML&service=cooking.stackexchange&printer=false

Is it correct?

1 Answer 1

2

Yes, you are explicitly telling it to sort on votes and it dutifully does so.

Drop the sort (or specify the default, activity) and the accepted answer will be listed at the top. see kevin's comments

Which brings up another interesting question, which I remember being discussed elsewhere but can't be bothered to search: how answers are shuffled around in the default sort.

If you have a monster question with 100's of answers and you use the default sort, which is somewhat random, no?, and page through, it seems that you are going to probably get unpredictable results.

So, the only way to reliably page through answers is to specify a non-default sort, which means that the accepted answer is not going to be pinned to the top of the list.

I don't see a simple way around this except to pull the accepted answer and manually add it to the head of the first page of results and omit it when encountered later in the paged operation.

but that is neither here nor there.

use accepted_answer_id to prefetch the accepted answer and insert it into the head of your list and ignore it if/when it comes around in results.

4
  • I'd also point out that there are vanishingly view questions (<100 glancing at a recent SO backup) with >100 answers, most of which are quite old. We've been strongly discouraging their creation for awhile. Commented Jul 22, 2010 at 16:22
  • @kevin - thanks for the clarification. with those numbers i would agree that the possible unpredictability of large answer sets represent an edge that doesn't warrant special treatment. Commented Jul 22, 2010 at 16:46
  • @system - the sites do not consume the api, they have direct access to the data and projecting the rules/constraints that we follow to the sites in order to understand the api is an exercise in futility. Sorry. About '@' replying: only the first @ is honored, the rest are ignored, so in this case, I am going to get the comment no matter because it is my post, but kevin needs an @kevin to get it. So you could say 'hey code and @kevin,..' or even '@kevin, what about @code's foo?' etc. Notice that there is only one replyToUser on comments? Commented Jul 23, 2010 at 8:04
  • @system - i think they do something similar to what I describe, probably in the sql. that's where it would be most efficient. Maybe kevin knows, and will tell us just for edification. Commented Jul 23, 2010 at 12:52

You must log in to answer this question.

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