Apply ACL restriction filters for a search query

Put this block in a function :)