function callback_search_conditions

callback_search_conditions($keys)

Provide search query conditions.

Callback for hook_search_info().

This callback is invoked by search_view() to get an array of additional search conditions to pass to search_data(). For example, a search module may get additional keywords, filters, or modifiers for the search from the query string.

This example pulls additional search keywords out of the $_REQUEST variable, (i.e. from the query string of the request). The conditions may also be generated internally - for example based on a module's settings.

Parameters

$keys: The search keywords string.

Return value

An array of additional conditions, such as filters.

Related topics

File

modules/search/search.api.php, line 367
Hooks provided by the Search module.

Code

function callback_search_conditions($keys) {
  $conditions = array();

  if (!empty($_REQUEST['keys'])) {
    $conditions['keys'] = $_REQUEST['keys'];
  }
  if (!empty($_REQUEST['sample_search_keys'])) {
    $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys'];
  }
  if ($force_keys = config('sample_search.settings')->get('force_keywords')) {
    $conditions['sample_search_force_keywords'] = $force_keys;
  }
  return $conditions;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!search!search.api.php/function/callback_search_conditions/7.x