コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getQueryTypesForFacet(FacetInterface $facet)
 {
     // Get our Facets Field Identifier, which is equal to the Search API Field
     // identifier.
     $field_id = $facet->getFieldIdentifier();
     // Get the Search API Server.
     $server = $this->index->getServerInstance();
     // Get the Search API Backend.
     $backend = $server->getBackend();
     $fields = $this->index->getFields();
     foreach ($fields as $field) {
         if ($field->getFieldIdentifier() == $field_id) {
             return $this->getQueryTypesForDataType($backend, $field->getType());
         }
     }
     throw new InvalidQueryTypeException($this->t("No available query types were found for facet @facet", ['@facet' => $facet->getName()]));
 }
コード例 #2
0
ファイル: Query.php プロジェクト: curveagency/intranet
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // Prepare the query for execution by the server.
     $this->preExecute();
     // Execute query.
     $response = $this->index->getServerInstance()->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;
 }
コード例 #3
0
ファイル: Utility.php プロジェクト: curveagency/intranet
 /**
  * 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->getServerInstance();
         } 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];
 }
コード例 #4
0
ファイル: Index.php プロジェクト: curveagency/intranet
 /**
  * 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)
 {
     // Asserts that the index was enabled before saving and will still be
     // enabled afterwards. Otherwise, this method should not be called.
     assert('$this->status() && $original->status()', '::reactToServerSwitch should only be called when the index is enabled');
     if ($this->getServerId() != $original->getServerId()) {
         if ($original->isServerEnabled()) {
             $original->getServerInstance()->removeIndex($this);
         }
         if ($this->isServerEnabled()) {
             $this->getServerInstance()->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->getServerInstance()->updateIndex($this);
     }
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function getServerInstance()
 {
     return $this->entity->getServerInstance();
 }