Generalise performSearch to allow different query types.

This will allow us to avoid code duplication when doing "msearch"
queries.