Example #1
0
 /**
  * Sets an option for this search query.
  *
  * @param string $name
  *   The name of an option. The following options are recognized by default:
  *   - 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
  *     \Drupal\search_api\Query\Query::parseModes() for recognized parse
  *     modes.
  *   - offset: The position of the first returned search results relative to
  *     the whole result in the index.
  *   - limit: The maximum number of search results to return. -1 means no
  *     limit.
  *   - 'search id': A string that will be used as the identifier when storing
  *     this search in the Search API's static cache.
  *   - 'skip result count': If present and set to TRUE, the search's result
  *     count will not be needed. Service classes can check for this option to
  *     possibly avoid executing expensive operations to compute the result
  *     count in cases where it is not needed.
  *   - search_api_access_account: The account which will be used for entity
  *     access checks, if available and enabled for the index.
  *   - search_api_bypass_access: If set to TRUE, entity access checks will be
  *     skipped, even if enabled for the index.
  *   However, contrib modules might introduce arbitrary other keys with their
  *   own, special meaning. (Usually they should be prefixed with the module
  *   name, though, to avoid conflicts.)
  * @param mixed $value
  *   The new value of the option.
  *
  * @return mixed
  *   The option's previous value, or NULL if none was set.
  *
  * @see \Drupal\search_api\Query\QueryInterface::setOption()
  */
 public function setOption($name, $value)
 {
     if (!$this->shouldAbort()) {
         return $this->query->setOption($name, $value);
     }
     return NULL;
 }
Example #2
0
/**
 * Alter the query before executing the query.
 *
 * @param \Drupal\views\ViewExecutable $view
 *   The view object about to be processed.
 * @param \Drupal\search_api\Query\QueryInterface $query
 *   The Search API Views query to be altered.
 *
 * @deprecated Use hook_views_query_alter() instead.
 *
 * @see hook_views_query_alter()
 *
 * @todo Possibly remove this, since hook_views_query_alter() works just as well
 *   (with instanceof check and $query->getSearchApiQuery()).
 */
function hook_search_api_views_query_alter(\Drupal\views\ViewExecutable $view, \Drupal\search_api\Query\QueryInterface &$query) {
  if ($view->getPath() === 'search') {
    $query->setOption('custom_do_magic', TRUE);
  }
}