コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // Prepare the query for execution by the server.
     $this->preExecute();
     // Execute query.
     $response = $this->index->getServer()->search($this);
     // Postprocess the search results.
     $this->postExecute($response);
     // Store search for later retrieval for facets, etc.
     // @todo Figure out how to store the executed searches for the request.
     // search_api_current_search(NULL, $this, $response);
     return $response;
 }
コード例 #2
0
 /**
  * Retrieves the necessary type fallbacks for an index.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The index for which to return the type fallbacks.
  *
  * @return string[]
  *   An array containing the IDs of all custom data types that are not
  *   supported by the index's current server, mapped to their fallback types.
  */
 public static function getDataTypeFallbackMapping(IndexInterface $index)
 {
     // Check the static cache first.
     $index_id = $index->id();
     if (empty(static::$dataTypeFallbackMapping[$index_id])) {
         $server = NULL;
         try {
             $server = $index->getServer();
         } catch (SearchApiException $e) {
             // If the server isn't available, just ignore it here and return all
             // types.
         }
         static::$dataTypeFallbackMapping[$index_id] = array();
         /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type */
         foreach (\Drupal::service('plugin.manager.search_api.data_type')->getCustomDataTypes() as $type_id => $data_type) {
             if (!$server || !$server->supportsDataType($type_id)) {
                 static::$dataTypeFallbackMapping[$index_id][$type_id] = $data_type->getFallbackType();
             }
         }
     }
     return static::$dataTypeFallbackMapping[$index_id];
 }
コード例 #3
0
ファイル: Index.php プロジェクト: jkyto/agolf
 /**
  * Checks whether the index switched server and reacts accordingly.
  *
  * Used as a helper method in postSave(). Should only be called when the index
  * was enabled before the change and remained so.
  *
  * @param \Drupal\search_api\IndexInterface $original
  *   The previous version of the index.
  */
 protected function reactToServerSwitch(IndexInterface $original) {
   if ($this->getServerId() != $original->getServerId()) {
     if ($original->isServerEnabled()) {
       $original->getServer()->removeIndex($this);
     }
     if ($this->isServerEnabled()) {
       $this->getServer()->addIndex($this);
     }
     // When the server changes we also need to trigger a reindex.
     $this->reindex();
   }
   elseif ($this->isServerEnabled()) {
     // Tell the server the index configuration got updated
     $this->getServer()->updateIndex($this);
   }
 }
コード例 #4
0
ファイル: Utility.php プロジェクト: jkyto/agolf
  /**
   * Retrieves the necessary type fallbacks for an index.
   *
   * @param \Drupal\search_api\IndexInterface $index
   *   The index for which to return the type fallbacks.
   *
   * @return string[]
   *   An array containing the IDs of all custom data types that are not
   *   supported by the index's current server, mapped to their fallback types.
   */
  public static function getDataTypeFallbackMapping(IndexInterface $index) {
    // Check the static cache first.
    $index_id = $index->id();
    if (empty(static::$dataTypeFallbackMapping[$index_id])) {
      $server = NULL;
      try {
        $server = $index->getServer();
      }
      catch (SearchApiException $e) {
        // If the server isn't available, just ignore it here and return all
        // custom types.
      }
      static::$dataTypeFallbackMapping[$index_id] = array();
      /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type */
      foreach (\Drupal::service('plugin.manager.search_api.data_type')->getInstances() as $type_id => $data_type) {
        // We know for sure that we do not need to fall back for the default
        // data types as they are always present and are required to be
        // supported by all backends.
        if (!$data_type->isDefault() && (!$server || !$server->supportsDataType($type_id))) {
          static::$dataTypeFallbackMapping[$index_id][$type_id] = $data_type->getFallbackType();
        }
      }
    }

    return static::$dataTypeFallbackMapping[$index_id];
  }