Added sorting function to searchByQuery

Allows a variety of sorting of results.