public function SearchApiViewsQuery::add_orderby in Search API 7
Provides a sorting method as present in the Views default query plugin.
This is provided so that the "Global: Random" sort included in Views will work properly with Search API Views. Random sorting is only supported if the active search server supports the "search_api_random_sort" feature, though, otherwise the call will be ignored.
This method can only be used to sort randomly, as would be done with the default query plugin. All other calls are ignored.
Parameters
string|null $table: Only "rand" is recognized here, all other calls are ignored.
string|null $field: Is ignored and only present for compatibility reasons.
string $order: Either "ASC" or "DESC".
string|null $alias: Is ignored and only present for compatibility reasons.
array $params: The following optional parameters are recognized:
- seed: a predefined seed for the random generator.
See also
views_plugin_query_default::add_orderby()
File
- contrib/
search_api_views/ includes/ query.inc, line 168 - Contains SearchApiViewsQuery.
Class
- SearchApiViewsQuery
- Views query class using a Search API index as the data source.
Code
public function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) {
$server = $this
->getIndex()
->server();
if ($table == 'rand') {
if ($server
->supportsFeature('search_api_random_sort')) {
$this
->add_selector_orderby('search_api_random', $order);
if ($params) {
$this
->setOption('search_api_random_sort', $params);
}
}
else {
$variables['%server'] = $server
->label();
watchdog('search_api_views', 'Tried to sort results randomly on server %server which does not support random sorting.', $variables, WATCHDOG_WARNING);
}
}
}