コード例 #1
0
 /**
  * Enables a search index without a confirmation form.
  *
  * @param \Drupal\search_api\IndexInterface $search_api_index
  *   The index to be enabled.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   The response to send to the browser.
  */
 public function indexBypassEnable(IndexInterface $search_api_index)
 {
     // Enable the index.
     $search_api_index->setStatus(TRUE)->save();
     // \Drupal\search_api\Entity\Index::preSave() doesn't allow an index to be
     // enabled if its server is not set or disabled.
     if ($search_api_index->status()) {
         // Notify the user about the status change.
         drupal_set_message($this->t('The search index %name has been enabled.', array('%name' => $search_api_index->label())));
     } else {
         // Notify the user that the status change did not succeed.
         drupal_set_message($this->t('The search index %name could not be enabled. Check if its server is set and enabled.', array('%name' => $search_api_index->label())));
     }
     // Redirect to the index's "View" page.
     $url = $search_api_index->toUrl('canonical');
     return $this->redirect($url->getRouteName(), $url->getRouteParameters());
 }
コード例 #2
0
 /**
  * Creates an indexing batch for a given search index.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The search index for which items should be indexed.
  * @param int|null $batch_size
  *   (optional) Number of items to index per batch. Defaults to the cron limit
  *   set for the index.
  * @param int $limit
  *   (optional) Maximum number of items to index. Defaults to indexing all
  *   remaining items.
  *
  * @throws \Drupal\search_api\SearchApiException
  *   Thrown if the batch could not be created.
  */
 public static function create(IndexInterface $index, $batch_size = NULL, $limit = -1)
 {
     // Check if the size should be determined by the index cron limit option.
     if ($batch_size === NULL) {
         // Use the size set by the index.
         $batch_size = $index->getOption('cron_limit', \Drupal::config('search_api.settings')->get('default_cron_limit'));
     }
     // Check if indexing items is allowed.
     if ($index->status() && !$index->isReadOnly() && $batch_size !== 0 && $limit !== 0) {
         // Define the search index batch definition.
         $batch_definition = array('operations' => array(array(array(__CLASS__, 'process'), array($index, $batch_size, $limit))), 'finished' => array(__CLASS__, 'finish'), 'progress_message' => static::t('Completed about @percentage% of the indexing operation (@current of @total).'));
         // Schedule the batch.
         batch_set($batch_definition);
     } else {
         $args = array('%size' => $batch_size, '%limit' => $limit, '%name' => $index->label());
         throw new SearchApiException(new FormattableMarkup('Failed to create a batch with batch size %size and limit %limit for index %name', $args));
     }
 }
コード例 #3
0
ファイル: Query.php プロジェクト: jkyto/agolf
 /**
  * Constructs a Query object.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The index the query should be executed on.
  * @param \Drupal\search_api\Query\ResultsCacheInterface $results_cache
  *   The results cache that should be used for this query.
  * @param array $options
  *   (optional) Associative array of options configuring this query. See
  *   \Drupal\search_api\Query\QueryInterface::setOption() for a list of
  *   options that are recognized by default.
  *
  * @throws \Drupal\search_api\SearchApiException
  *   Thrown if a search on that index (or with those options) won't be
  *   possible.
  */
 public function __construct(IndexInterface $index, ResultsCacheInterface $results_cache, array $options = array()) {
   if (!$index->status()) {
     throw new SearchApiException(new FormattableMarkup("Can't search on index %index which is disabled.", array('%index' => $index->label())));
   }
   if (isset($options['parse mode'])) {
     $modes = $this->parseModes();
     if (!isset($modes[$options['parse mode']])) {
       throw new SearchApiException(new FormattableMarkup('Unknown parse mode: @mode.', array('@mode' => $options['parse mode'])));
     }
   }
   $this->index = $index;
   $this->resultsCache = $results_cache;
   $this->options = $options + array(
     'conjunction' => 'AND',
     'parse mode' => 'terms',
     'filter class' => '\Drupal\search_api\Query\Filter',
     'search id' => __CLASS__,
   );
   $this->filter = $this->createFilter('AND');
 }
コード例 #4
0
ファイル: Query.php プロジェクト: curveagency/intranet
 /**
  * Constructs a Query object.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The index the query should be executed on.
  * @param \Drupal\search_api\Query\ResultsCacheInterface $results_cache
  *   The results cache that should be used for this query.
  * @param array $options
  *   (optional) Associative array of options configuring this query. See
  *   \Drupal\search_api\Query\QueryInterface::setOption() for a list of
  *   options that are recognized by default.
  *
  * @throws \Drupal\search_api\SearchApiException
  *   Thrown if a search on that index (or with those options) won't be
  *   possible.
  */
 public function __construct(IndexInterface $index, ResultsCacheInterface $results_cache, array $options = array())
 {
     if (!$index->status()) {
         throw new SearchApiException(new FormattableMarkup("Can't search on index %index which is disabled.", array('%index' => $index->label())));
     }
     $this->index = $index;
     $this->resultsCache = $results_cache;
     $this->options = $options + array('conjunction' => 'AND', 'search id' => __CLASS__);
     $this->conditionGroup = $this->createConditionGroup('AND');
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function status()
 {
     return $this->entity->status();
 }