Modify Search API sort order in Drupal using a hook

If you need to change the sort order of the Drupal 7 Search API using code, here is an example using hook_search_api_query_alter: