function search_expression_extract

Extracts a module-specific search option from 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 extract from.

$option: The name of the option to retrieve from the search expression.

Return value

The value previously stored in the search expression for option $option, if any. Trailing spaces in values will not be included.

2 calls to search_expression_extract()
SearchExpressionInsertExtractTest::testInsertExtract in drupal/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php
Tests search_expression_insert() and search_expression_extract().
SearchQuery::setOption in drupal/core/modules/search/lib/Drupal/search/SearchQuery.php
Applies a search option and removes it from the search query string.

File

drupal/core/modules/search/search.module, line 886
Enables site-wide keyword searching.

Code

function search_expression_extract($expression, $option) {
  if (preg_match('/(^| )' . $option . ':([^ ]*)( |$)/i', $expression, $matches)) {
    return $matches[2];
  }
}