Deduplicate search code

Instead of duplicating the search code across each backend, move it to
commands.ml

Signed-off-by: John Else <john.else@citrix.com>