4

How do I search for questions with a certain tag and that have been awarded a badge? I.e. search for all questions tagged with and have earned the badge Favorite Question

I have found out how to search by either one separately: c++, Favorite Question.

So is this even possible, or can you currently only see them separately?

2 Answers 2

3

Badges aren't indexed for searching in that manner at all, so at the moment this is unfortunately not possible.

2

Unfortunately, the 'badges' table in the Data Explorer does not contain post information (here is an old, popular feature request to enable this).

For this particular badge, you can check it with the following query on the 'votes' table, where marks-as-favorite are stored:

SELECT p.id AS [Post Link], COUNT(*) AS Favorites
  FROM votes AS v
  INNER JOIN posts AS p ON v.postid = p.id
  INNER JOIN posttags AS pt ON p.id = pt.postid
  INNER JOIN tags AS t ON t.id = pt.tagid
  WHERE v.votetypeid = 5 -- Marked as favorite
    AND t.tagname = lower(##TagName:string##)
  GROUP BY p.id
  HAVING COUNT(*) >= ##NumberOfFavorites:int## 
  ORDER BY COUNT(*)

The first results (for parameters 'c++', 25) are the following questions:

Compiling Qt 4.8.x for Visual Studio 2012

Decent profiler for Windows?

What are the advantages of using the C++ Boost libraries?

Note that SEDE data is refreshed once a week, on Sunday morning.

EDIT:

As @rene points out, the following query will probably be faster, as it saves a join:

SELECT p.id AS [Post Link], p.favoritecount
  FROM posts AS p
  INNER JOIN posttags AS pt ON p.id = pt.postid
  INNER JOIN tags AS t ON t.id = pt.tagid
  WHERE t.tagname = lower(##TagName:string##)
    AND p.favoritecount >= ##NumberOfFavorites:int## 
  ORDER BY p.favoritecount
1
  • 1
    You beat me to it by mere seconds .... for this particular case the posts table holds a denormalized field: favoritecount which will spare you all those joins but for other badges to get them linked to a post your approach is the way to go.
    – rene
    Jul 19, 2016 at 6:31

You must log in to answer this question.

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