Here's what I know for Ontario Police.
You cannot be arbitrarily searched.
An officer can search you for his safety and yours. He cannot go into your pockets or any personal effects unless he has reasonable and probable grounds that you are carrying something that may endanger their live or yours - This is commonly known as a patdown
You can be searched if during the patdown if the officer feels any type of weapon or reasonably suspicious object.
You will be searched if you have been arrested.
You can also consent to a search and at any time revoke that consent.
“I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours.” Stephen Roberts