3

How can I search for which of my questions user 13 has answered?

None of these work:

  • "user:me user:13"
  • "user:me thirteen" (where thirteen is the user's name)
  • "inquestion:me user:13"

Is there a way to do this?

1
  • @yellowantphil I guess if there's not a way to do it with regular search I'll have to go figure out SEDE. Commented Nov 4, 2016 at 18:28

3 Answers 3

5

Here is a SEDE query that lists a specific user's answers to a specific user's questions:

select a.Id as [Post Link], a.CreationDate,
    case when p.AcceptedAnswerId = a.Id then N'✓' else '' end as Accepted,
    a.Score as [Answer Score]
from Posts a
inner join Posts p on a.ParentId = p.Id
where a.OwnerUserId = ##AnswererId##
    and p.OwnerUserId = ##AskerId##
order by a.CreationDate desc

The results are updated every Sunday at 3:00 UTC.

2
  • Well this is pretty magical. I can't remember any database stuff, is there a way to add the check for whether I accepted the user's answer? Commented Nov 4, 2016 at 19:01
  • Looks amazing, I'll accept on Monday if I can't get any answers on how to do it with just regular search. Commented Nov 4, 2016 at 19:11
4

With a bit of Stack Snippet magic and the use of the Stack API you can search in live data on your questions and their answers:

(function () {
  // what we are calling
  var api = {
    url: 'https://api.stackexchange.com/2.2/',
    endpoint: 'users/{0}/questions',
    params: { 
      site: 'stackoverflow',
      pagesize: 100,
      order: 'desc',
      sort: 'activity',
      Filter: '!6hYwaMGTMGHoxHfxsMZeS7MZ-zdSfzKByj6w*OnEd1W_ll',
      key: 'JBN9WXWxwrcnAj7WEEytmQ(('
      }
    },
    userid = 4342498;
    
  // glue both url and query string to one
  function createUrl(ap) {
    var ep = ap.url + ap.endpoint +'?',
     nv = [];
    $.each(ap.params, function (k,v) {
       nv.push(k + '=' + v);
    });
    console.log(ep + nv.join('&'));
    return ep + nv.join('&');
  }
 
  // add an answer to the final result
  function addResult(a) {
    var list = $('#Q');
    list.append(
            $('<div></div>').append(
            $('<a></a>')
              .attr('href', a.link)
              .attr('title', a.owner.display_name)
              .html(a.title)
            ));
  }
  
  // process each answer in the answer array
  function handleAnswers(answers) {
    var i, a;
    for(i = 0; i < answers.length; i = i + 1) {
      a = answers[i];
      // is this answer owned by the correct user?
      if (a.owner && a.owner.user_id === userid) {
        addResult(a);
      }
    }
  }
  
  // handle all question in the iteme array
  function handleItems(items) {
    var i, q;
    for(i = 0; i < items.length; i = i +1) {
          q = items[i];
          // don't bother handling if no answers
          if (q.answer_count>0) {
            handleAnswers(q.answers);       
          }
      }
  }
  
  // load a page of for questions of the owner
  function load(page) {
    api.params.page = page;
    $('#load').hide();
    $.get(createUrl(api), function (data) {
      var backoff = data.backoff || 0;
      
      handleItems(data.items);
      
      if (data.has_more) {
        // make sure to honor the backoff
        // or risk being IP banned
        window.setTimeout( function () {
              load(page +1);
            }, 
           backoff * 1000);  
      } else {
           // done
      }
    });
  }

  // bind the start to the button
  $('#go').on('click', function() {
    // owner questions
    api.endpoint = api.endpoint.replace('{0}', $('#ownid').val());
    // answer owner
    userid = parseInt($('#userid').val(),10); 
    // start at page 1
    load(1);
  });
  
}());
label {display: inline-block; width: 150px; }
div { padding: 2px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="error" style="display:none">
</div>
<h2>Find answers from a specific user</h2>
<div>
  <label for="ownid">My own user id:</label> 
  <input id="ownid" type='text' value='2642059' />
</div>
<div>
  <label for="userid">User Id on answers:</label> 
  <input id="userid" type='text' value='4342498' />
</div>
<div>
  <button id='go'>Search</button>
</div>
<div id="Q">
  
</div>
<div id="load" style="display:none">
 Click to load more ...
</div>

What I'm basically doing here is to fetch /users/{id}/questions from the Stack API. I then iterate over the items that contain question types. Due to the filter I applied the answers for the question are also returned. In each answer I compare the user_id of the owner with the given value in the search form. When matched the result is added to the result in the HTML DOM.

3
  • Amazing. The thing I'm not understanding is where did the Filter and key values come from? Commented Nov 7, 2016 at 11:51
  • 1
    @JonathanMee A filter can be build on each endpoint under the default filter pop-up (at the right of the query form). That gives a value when saved and can then be copied. The key is obtained if you register an app at Stack Apps. Once registered you can share that key so users of the app get higher API quota. And when you abuse it, I get the complaints from SE DevOps ;)
    – rene
    Commented Nov 7, 2016 at 15:36
  • Thanks for the awesome answer. I wish that I could accept both you and yellowantphil's answers this has been very enlightening for me in defining the powerful search functionality available to us. Commented Nov 7, 2016 at 15:39
1

yellowantphil's answer really answered my question. But I had also asked if I could filter by only accepted answers. I added another join to yellowantphil's answer to solve this, and I thought it might be helpful to future readers, so I figured I'd post it here:

select a.Id as [Post Link], a.CreationDate
from Posts a
join Posts p on a.ParentId = p.Id
join Posts v on v.AcceptedAnswerId = a.Id
where a.OwnerUserId = ##AnswererId##
and p.OwnerUserId = ##AskerId##
order by a.CreationDate desc

Live Example

You must log in to answer this question.

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