diff --git a/contrib/search_api_views/includes/query.inc b/contrib/search_api_views/includes/query.inc index 82588a6..8935fe6 100644 --- a/contrib/search_api_views/includes/query.inc +++ b/contrib/search_api_views/includes/query.inc @@ -126,8 +126,10 @@ class SearchApiViewsQuery extends views_plugin_query { * * @param $selector * The field to sort on. All indexed fields of the index are valid values. - * In addition, the special fields 'search_api_relevance' (sort by - * relevance) and 'search_api_id' (sort by item id) may be used. + * In addition, the special fields may be used: + * - 'search_api_relevance' (sort by relevance) + * - 'search_api_id' (sort by item id) + * - 'search_api_random' (random sort) * @param $order * The order to sort items in - either 'ASC' or 'DESC'. Defaults to 'ASC'. */ @@ -136,6 +138,16 @@ class SearchApiViewsQuery extends views_plugin_query { } /** + * 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. diff --git a/includes/query.inc b/includes/query.inc index b005cf7..6d4fa74 100644 --- a/includes/query.inc +++ b/includes/query.inc @@ -585,6 +585,7 @@ class SearchApiQuery implements SearchApiQueryInterface { $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)));