I think the mapserver (for historical reasons, according to the mapscript docs) only searches layers where the template field is non-null. Perhaps you could try something like queryLayer.Template="xyz";