You are here

function search_api_current_search in Search API 7

Stores or retrieves a search executed in this page request.

Static storage for the searches executed during the current page request. Can used to store an executed search, or to retrieve a previously stored search.

Parameters

$search_id: For pages displaying multiple searches, an optional ID identifying the search in questions. When storing a search, this is filled automatically, unless it is manually set.

SearchApiQuery $query: When storing an executed search, the query that was executed. NULL otherwise.

array $results: When storing an executed search, the returned results as specified by SearchApiQueryInterface::execute(). An empty array, otherwise.

Return value

array If a search with the specified ID was executed, an array containing ($query, $results) as used in this function's parameters. If $search_id is NULL, an array of all executed searches will be returned, keyed by ID.

6 calls to search_api_current_search()
SearchApiFacetapiAdapter::getCurrentSearch in contrib/search_api_facetapi/plugins/facetapi/adapter.inc
Helper method for getting a current search for this searcher.
SearchApiFacetapiDate::build in contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc
Initializes the facet's build array.
SearchApiFacetapiTerm::build in contrib/search_api_facetapi/plugins/facetapi/query_type_term.inc
Initializes the facet's build array.
SearchApiQuery::execute in includes/query.inc
Executes this search query.
SearchApiViewsCache::cache_get in contrib/search_api_views/includes/plugin_cache.inc
Overrides views_plugin_cache::cache_get().

... See full list

File

./search_api.module, line 1923
Provides a flexible framework for implementing search services.

Code

function search_api_current_search($search_id = NULL, SearchApiQuery $query = NULL, array $results = array()) {
  $searches =& drupal_static(__FUNCTION__, array());
  if (isset($query)) {
    if (!isset($search_id)) {
      $search_id = $query
        ->getOption('search id');
    }
    $base = $search_id;
    $i = 0;
    while (isset($searches[$search_id])) {
      $search_id = $base . '-' . ++$i;
    }
    $searches[$search_id] = array(
      $query,
      $results,
    );
  }
  if (isset($search_id)) {
    return isset($searches[$search_id]) ? $searches[$search_id] : NULL;
  }
  return $searches;
}