You are here

search_api_multi.module in Search API Multi-Index Searches 7

File

search_api_multi.module
View source
<?php

/**
 * Implements hook_views_api().
 */
function search_api_multi_views_api() {
  if (module_exists('search_api_views')) {
    return array(
      'api' => '3.0-alpha1',
      'path' => drupal_get_path('module', 'search_api_multi') . '/views',
    );
  }
}

/**
 * Creates a multi-index search query.
 *
 * For backwards-compatibility reasons, the options can be passed as either the
 * first or the second parameter, the other one is ignored.
 *
 * @param $options
 *   Associative array of options configuring this query. Recognized options
 *   are:
 *   - conjunction: The type of conjunction to use for this query - either
 *     'AND' or 'OR'. 'AND' by default. This only influences the search keys,
 *     filters will always use AND by default.
 *   - 'parse mode': The mode with which to parse the $keys variable, if it
 *     is set and not already an array. See SearchApiMultiQuery::parseModes() for
 *     recognized parse modes.
 *   - languages: The languages to search for, as an array of language IDs.
 *     If not specified, all languages will be searched. Language-neutral
 *     content (LANGUAGE_NONE) is always searched.
 *   - offset: The position of the first returned search results relative to
 *     the whole result.
 *   - limit: The maximum number of search results to return. -1 means no
 *     limit.
 *   - 'filter class': Can be used to change the SearchApiQueryFilterInterface
 *     implementation to use.
 *   - 'search id': A string that will be used as the identifier when storing
 *     this search in the static cache.
 *   All options are optional.
 * @param array $options2
 *   Deprecated. Exactly the same as $options. Will be used if $options is no
 *   array.
 *
 * @return SearchApiMultiQueryInterface
 *   A query object for searching multiple indexes.
 */
function search_api_multi_query($options = array(), array $options2 = array()) {
  $options = is_array($options) ? $options : $options2;
  return new SearchApiMultiQuery($options);
}

/**
 * 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.
 *
 * @param $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.
 * @param SearchApiMultiQuery $query
 *   When storing an executed search, the query that was executed. NULL
 *   otherwise.
 * @param array $results
 *   When storing an executed search, the returned results as specified by
 *   SearchApiMultiQueryInterface::execute(). An empty array, otherwise.
 *
 * @return 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.
 */
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;
}

Functions

Namesort descending Description
search_api_multi_current_search Static store for the multi-index searches executed on the current page.
search_api_multi_query Creates a multi-index search query.
search_api_multi_views_api Implements hook_views_api().