diff --git a/sites/all/modules/search_api/contrib/search_api_views/includes/query.inc b/sites/all/modules/search_api/contrib/search_api_views/includes/query.inc index 36bc232..eb69b61 100644 --- a/sites/all/modules/search_api/contrib/search_api_views/includes/query.inc +++ b/sites/all/modules/search_api/contrib/search_api_views/includes/query.inc @@ -134,10 +134,20 @@ public function add_selector_orderby($selector, $order = 'ASC') { $this->query->sort($selector, $order); } /** + * Implement the same add_orderby() method as views_plugin_query_default so + * that Views' "Global: Random" sort can be used. + */ + function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) { + if ($table == 'rand') { + $this->add_selector_orderby('search_api_random', $order); + } + } + + /** * Defines the options used by this query plugin. * * Adds some access options. */ public function option_definition() { diff --git a/sites/all/modules/search_api/includes/query.inc b/sites/all/modules/search_api/includes/query.inc index e9ccc20..96d1125 100644 --- a/sites/all/modules/search_api/includes/query.inc +++ b/sites/all/modules/search_api/includes/query.inc @@ -580,10 +580,11 @@ public function sort($field, $order = 'ASC') { $fields = $this->index->options['fields']; $fields += array( 'search_api_relevance' => array('type' => 'decimal'), 'search_api_id' => array('type' => 'integer'), + 'search_api_random' => array('type' => 'integer'), ); if (empty($fields[$field])) { throw new SearchApiException(t('Trying to sort on unknown field @field.', array('@field' => $field))); } $type = $fields[$field]['type'];