They don't always do a good job of that, though. Yesterday I was searching for documentation for a JS validation library (Joi), and a specific search string ("Joi deny substring") returned some... pornier search results as the top five. It was somewhat redeemed with the sixth result being the one I was looking for.
I misread your comment. Google does indeed return porny stuff for this, and ddg does not. In both engines, your comment is the top of the search results. :-)
And this was with safe search on.