Filter posts (or CPT) which user can’t access

The only way of checking and filtering the posts not accessible by the current user is during the post processing of the search results.

What is this, and where do I put this custom code?

add_filter( 'asp_results', 'asp_filter_posts_by_capability', 10, 1 );
function asp_filter_posts_by_capability( $results ) {
foreach ($results as $k => &$r ) {
if ( !current_user_can('read_post', $r->id) )
unset($results[$k]);
}
return $results;
}