for a police officer to search you on the streets (legally) they need A. your consent,which you would be a dumbass to give in most cases B. search after incident of arrest i.e.you got caught doing something stupid so they go through your shit. C.they have some form of probable cause. like you have paint on your hands or your lookin mad intoxicated. if your underaged and out at night your violating curfew and they tend to have a right to search your shit. idk if its a right but i just know they will. probable cause is basicly some form of evidence that leads a police to believe that you are up to no good and have some shit on you. it could be all types of shit. all of which you can debate in court and if the folks find your arguement valid and the search wasnt up to code all that evidence is thrown out.and this usualy means they drop the case..not always thoguh
for your house to get raided: this is just based off personal experience.
-you get arrested for graffiti
-you are caught with sketches.or pics on your phone like dude said
-someone snitches on you, and if you have priors that tends to be enough for them to be able to get a judge to sign a search warrant
-you let them in. GOD FORBID YOU EVER DO THIS. if you see police at your door dont answer it. cops have been known to slide their way through open doors and once their in thats basicly like saying "your free to look around officer"
not a lawyer or nothing.just stuff ive read or heard and stuff that ive had experience with.hope that helps for people who really want to know.