I am looking at this also. My problem is different since I am not sure how to address the correct layer. I found this:
http://www.azavea.com/blogs/labs/2011/06/using-the-cql_filter-parameter-with-openlayers-wms-layers/
But I think I understand your problem. You would have to make a function that grabs the search term (or static search) and sends the call differently to each layer. I am using a search box and checkbox to where to search. Click the checkbox (MyRadios) and enter the search query. On the form have a submit trigger the function and supress default action. I use ExtJS but you would get the value of the checked radio button along with the input field. If you want the radio button option you can use an if statement to change the param according to the checked radio value.
function CQLfilter(param){ //param here would be the search value
// send different request to different layers
req1 = "field1 LIKE '%" + param + "%'";
req2 = "field2 LIKE '%" + param + "%'";
req3 = "field3 LIKE '%" + param + "%'";
wms_layer1.mergeNewParams({'CQL_FILTER': req1});
wms_layer2.mergeNewParams({'CQL_FILTER': req1});
wms_layer3.mergeNewParams({'CQL_FILTER': req1})
}
function resetCQLfilters() {
delete wms_layer1.params.CQL_FILTER;
wms_layer1.redraw();
delete wms_layer2.params.CQL_FILTER;
wms_layer2.redraw();
delete wms_layer3.params.CQL_FILTER;
wms_layer3.redraw();
}
This is just a shot. My problem is I am using a function to create and load the layers but do not know how I then get the layer name. Do you know what my layername would be in my example?
var createWmsLayer = function(name, url, params, options) {
map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));
};
createWmsLayer("<span class='locc'>Ikke listet</span>", "http://localhost/geoserver/wms",
{layers: 'gbif_ns:ikke_listet',format: 'image/png', transparent: 'true'}, {singleTile: true, ratio: 1, isBaseLayer:false, visibility: false}
);
~asle