function search_expression_insert
Adds a module-specific search option to a search expression.
Search options are added using search_expression_insert(), and retrieved using search_expression_extract(). They take the form option:value, and are added to the ordinary keywords in the search expression.
Parameters
$expression: The search expression to add to.
$option: The name of the option to add to the search expression.
$value: The value to add for the option. If present, it will replace any previous value added for the option. Cannot contain any spaces or | characters, as these are used as delimiters. If you want to add a blank value $option: to the search expression, pass in an empty string or a string that is composed of only spaces. To clear a previously-stored option without adding a replacement, pass in NULL for $value or omit.
Return value
$expression, with any previous value for this option removed, and a new $option:$value pair added if $value was provided.
3 calls to search_expression_insert()
- node_search_validate in modules/
node/ node.module - Form validation handler for node_form_alter().
- SearchExpressionInsertExtractTestCase::testInsertExtract in modules/
search/ search.test - Tests search_expression_insert() and search_expression_extract().
- SearchQuery::setOption in modules/
search/ search.extender.inc - Applies a search option and removes it from the search query string.
File
-
modules/
search/ search.module, line 900
Code
function search_expression_insert($expression, $option, $value = NULL) {
// Remove any previous values stored with $option.
$expression = trim(preg_replace('/(^| )' . $option . ':[^ ]*/i', '', $expression));
// Set new value, if provided.
if (isset($value)) {
$expression .= ' ' . $option . ':' . trim($value);
}
return $expression;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.