9

I want to find all stack snippets for a given language/technology.

Is there a way to query for this?

2
  • 1
    If you want to see "cool" things done with Stack Snippets, check out the Stack Snippets Sandbox... May 9, 2017 at 14:50
  • Language? Snippets are css/html/javascript. What languages are you talking about?
    – user1228
    May 9, 2017 at 16:33

1 Answer 1

3

It seems impossible with the top search bar.

However, you can search for snippets with the SEDE, using simple pattern matching.

For example, this query finds all answers with a js snippet:

SELECT Id AS [Post Link], *
FROM Posts
WHERE
  CreationDate > '2019-01-01'
  AND
  LOWER(Body) LIKE LOWER('%snippet: js%')

Some other narrowing of the query is needed, because SEDE is too slow to handle pattern search in all the question bodies. This example query filters for Posts created after 2019-01-01.

6
  • 1
    doing a lower on both sides of the expression is pretty expensive. Consider using Body LIKE '%snippet: js%' collate SQL_Latin1_General_CP1_CI_AI
    – rene
    May 27, 2019 at 8:53
  • @rene Thanks, it is very useful! Although my experience is that the real bottleneck is that LIKE is ... slow.
    – peterh
    May 27, 2019 at 8:59
  • Yeah, it needs to do a table scan. I expect using collate will reduce memory pressure bit. It doesn't reduce the I/O calls which is probably the bulk of the processing. For these type of queries a full text index would be beneficial. On MSE there are FR's for that but given how SEDE is updated adding full text indexes is not feasible. So your approach with limiting the numbers of rows to search is the only one that can work on SEDE
    – rene
    May 27, 2019 at 9:30
  • @rene Utf8 regexp matching is much slower also on Linux, although it shouldn't be so. The DB here is in utf8, but the overwhelming majority of the content is 7-bit ascii, that can make the pattern match maybe much faster.
    – peterh
    May 27, 2019 at 9:51
  • It seems like a site about code should spend some time making a code friendly search option.
    – gman
    Dec 28, 2020 at 16:03
  • @gman They use elasticsearch on the backend, it is very flexible and surely they could do that quite easily. I think if you, as a 80k+ SO user, ask for this on the MSO or on the MSE, you will get above average community support (other question, what the company will do).
    – peterh
    Dec 28, 2020 at 17:54

You must log in to answer this question.

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