Okay, here is the problem:
Certain questions contain more than one page's worth of answers. Given a sort method and an answer id, how can we figure out which page the answer is on?
Any suggestions are welcome.
These are two simple methods in meta-language:
1. Pulls a pagesize number of answers, page after page, checking the presence of the given accepted_answer_id
def get_accepted_answer_page(question_id, answer_id, sort, pagesize): page = 1 while(True): answers_page_ids = get_answers_ids_with_API_method(question_id, sort, page, pagesize) if accepted_answer_id in answers_page_ids : return page else: page ++
2. Pulls all the answers ids using the fastest/lightest API method (questions/id/answers, pagesize=100, body=false..), get the index of the accepted_answer_id on this list and finally find the page dividing accepted_answer_id position by the pagesize
def get_accepted_answer_page(question_id, answer_id, sort, pagesize): answers_ids = get_all_answers_ids_with_the_fastest_lightest_API_method(question_id, sort) accepted_answer_id_position = get_accepted_answer_index (answers_ids) + 1 accepted_answer_page = (accepted_answer_id_position / pagesize) +1 if accepted_answer_id_index MOD pagesize == 0 : accepted_answer_page -- return accepted_answer_page
Why go through the question to get an answer you already have?
You have an answer id, so you can get all of its information.
I suppose you could pull all answers from a question and store them in a list is a static sorted order. Then, you would know the page the answer is on given the entire list.
It is far less memory efficient, but it will be much easier to figure out.