Can a male officer search a female?

Question Details:

My boyfriend and I were arguing; the cops were called by someone pertaining a domestic call. When they arrived I stated we were just arguing nothing physical; they stated they did not believe me and proceeded to arrest my boyfriend. He then began resisting arrest. While they were trying to subdue him an officer walked me to the back of his car and began searching me. I asked him what I had done. He said my boyfriend had a pill on him and now he wanted to search me. He stuck his hand in my pocket and pulled out a pill. There were 2 to 3 male officers present; no female officers. Can I fight this or was it legal? Important Notice