5

I was doing a little cleanup in a tag recently, and was wanting to find any questions with only that tag, since that often means they weren't tagged very well and are in need of a few more.

Unfortunately, there was no good way in the advanced search to do this. You can exclude a specific tag, but there doesn't appear to be a way to exclude all but one (or a subset). Also, tags can't be quantified with a range operator like, for example, answers can (i.e. answers:3 for all questions with 3 or more answers).

Is there a way to do this with the current search that I've overlooked? If not, could a tags:N search option be added to narrow down the search based on the number of tags a question has?

4

1 Answer 1

1

I'm fairly positive that there is no way to do this with the advanced search (and I support the addition of a tag count as a search operator, although I don't strongly support it as it ideally should be rare and is a relatively unusual use case), however, in the mean time, you can do this through SEDE if you don't mind the data being up to a week old (it's updated weekly), by using the Tags field in Posts, which is a list of tags enclosed in angle brackets:

SELECT TOP 50
  Id [Post Link], Tags, *
FROM
  Posts
WHERE
  Tags = '<java>'  -- Tag name (case-sensitive) inside <>'s
ORDER BY
  CreationDate DESC

You can also do a join on PostTags and Tags then search by Tags.TagName but the query becomes more complex to look for posts with just a single tag.

To make it more reusable you can use a parameter field for the tag name, for example in this query just type the tag name in the box below the query then press Run Query.

Replace Tags = '<java>' with Tags LIKE '%<java>%' to get any post with that tag instead of posts with just that tag.


Also, if you want to find any question with just one tag, regardless of the tag, you can use a query like this:

SELECT TOP 50
  Id [Post Link], Tags, *
FROM
  Posts
WHERE
  LEN(Tags) - LEN(REPLACE(Tags, '<', '')) = 1 -- # of <'s = # of tags
ORDER BY
  CreationDate DESC

An alternate trick in the case of just one tag is Tags NOT LIKE '%><%'.


More complete docs on the SEDE schema can be found here.

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