Mr. Kennedy is correct, this analysis is very fact specific. The answer used to be generally yes, but a recent US Supreme Court case restricted this type of search in many cases. If you were arrested for something the police found in such a search, you should consult a criminal attorney.