combine plugin/theme search code

besides reducing duplication, it also fixes an undefined $fields
variable notice
Merge pull request #828 from wp-cli/fix-search

Misc plugin/theme search improvements