You are here

function search_api_multi_current_search in Search API Multi-Index Searches 7

Static store for the multi-index searches executed on the current page.

Can either be 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.

SearchApiMultiQuery $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 SearchApiMultiQueryInterface::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.

1 call to search_api_multi_current_search()
SearchApiMultiQuery::execute in ./search_api_multi.query.inc
Implements SearchApiMultiQueryInterface::execute().

File

./search_api_multi.module, line 76

Code

function search_api_multi_current_search($search_id = NULL, SearchApiMultiQuery $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($searches[$search_id])) {
    return $searches[$search_id];
  }
  return $searches;
}