Programmatically Setting Content Ranking Factors For Drupal Search I've added a dropdown to Drupal search page interface. I would like for users to be able to select this control to sort results according to Date or Keyword Relevance.

I'm able to get the dropdown value in a submit handler, however, I don't know how to programmatically alter the weight of 'keyword relevance' and 'date'.

Here is my submit handler. Any help would be greatly appreciated.

function test_sort_form_submit_handler($form, &amp;$form_state) {
  drupal_set_message("Drop Down Value Is: " . $form_state['values']['search_sort']);
}
I would do this with a view instead of trying to tweak Drupal's search page:


Create a view
Add the filter "Search: Search Keywords" and expose it
Add two sort criteria: your date field and the "Search: Score" field and expose both of them
In Advanced > Exposed form > settings, check "Allow people to choose the sort order" if you want to give people that option
Add the fields or setup the display as you prefer


You can set the default sort option by ordering the sort criteria and the asc/desc setting by choosing that option for the top criteria. You can also use the Better Exposed Filters module (full disclosure: I'm the maintainer) to combine the sort field and direction into a single dropdown and/or rewrite the text of the options.