Commit 4e367be9 authored by Benjamin Cizej's avatar Benjamin Cizej
Browse files

Issue #3264559: Compatibility with current Meilisearch v0.25

parent b6ad5a21
Loading
Loading
Loading
Loading
+1 −1
Changes for README.md: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ VERSIONS COMPATIBILITY
| Search API Meilisearch | meilisearch-php | Meilisearch |
|------------------------|-----------------|-------------|
| 1.0.0                  | 0.10.2          | 0.10.0      |
| 1.0.x-dev              | 0.12.0          | 0.12.0      |
| 1.0.x-dev              | 0.24.0          | 0.28.0      |

INSTALLATION
------------
+1 −1
Changes for composer.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -18,6 +18,6 @@
    },
    "require": {
        "drupal/core": "^8.4 || ^9",
        "meilisearch/meilisearch-php": "^0.13.0"
        "meilisearch/meilisearch-php": "^0.24.0"
    }
}
+1 −2
Changes for search_api_meilisearch.module: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@ function search_api_meilisearch_help($route_name, RouteMatchInterface $route_mat
  switch ($route_name) {
    // Name and description of the Search API MeiliSearch module.
    case 'help.page.search_api_meilisearch':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Adds MeiliSearch plugin for Search API.') . '</p>';
      return $output;

+27 −40
Changes for src/Api/MeiliSearchApiService.php: 27 added lines, 40 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ namespace Drupal\search_api_meilisearch\Api;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\search_api_meilisearch\Client\MeiliSearchClientFactoryInterface;
use Http\Client\Exception\NetworkException;
use MeiliSearch\Exceptions\HTTPRequestException;
use MeiliSearch\Exceptions\ApiException;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
@@ -73,7 +73,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function setMasterKey($key) {
  public function setMasterKey(string $key) {
    $this->masterKey = $key;
  }

@@ -102,8 +102,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
      $this->client = $this->clientFactory->getInstance($this->getUrl(), $this->getMasterKey());
      try {
        $this->client->version();
      }
      catch (\Exception $e) {
      } catch (\Exception $e) {
        throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
      }
    }
@@ -130,9 +129,8 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
   */
  public function getIndex(string $name) {
    try {
      return $this->connection()->getOrCreateIndex($name);
    }
    catch (\Exception $e) {
      return $this->connection()->getIndex($name);
    } catch (\Exception $e) {
      throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
    }
  }
@@ -142,12 +140,10 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
   */
  public function createIndex($attributes) {
    try {
      return $this->connection()->getOrCreateIndex($attributes);
    }
    catch (MeiliSearchApiException $e) {
      return $this->connection()->createIndex($attributes);
    } catch (MeiliSearchApiException $e) {
      return FALSE;
    }
    catch (HTTPRequestException $e) {
    } catch (ApiException $e) {
      return FALSE;
    }
  }
@@ -158,11 +154,9 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  public function removeIndex(string $index_name) {
    try {
      $this->connection()->deleteIndex($index_name);
    }
    catch (MeiliSearchApiException $e) {
    } catch (MeiliSearchApiException $e) {
      return FALSE;
    }
    catch (HTTPRequestException $e) {
    } catch (ApiException $e) {
      return FALSE;
    }

@@ -175,8 +169,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  public function listIndexes() {
    try {
      return $this->connection()->getAllIndexes();
    }
    catch (\Exception $e) {
    } catch (\Exception $e) {
      throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
    }
  }
@@ -210,7 +203,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  public function getDocuments(string $index_name, array $options = []) {
    $index = $this->getIndex($index_name);
    if ($index) {
      $documents = $index->getDocuments($options);
      $documents = $index->getDocuments();
      if (empty($documents)) {
        return FALSE;
      }
@@ -222,12 +215,12 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function deleteDocument(string $index_name, $id) {
    if ($index_name) {
      $index = $this->getIndex($index_name);
  public function deleteDocument(string $index, string $id) {
    if ($index) {
      $index = $this->getIndex($index);
      if ($index) {
        $index->deleteDocument($id);
        return $this->getDocuments($index_name);
        return $this->getDocuments($index);
      }
    }
    return FALSE;
@@ -237,8 +230,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
   * {@inheritdoc}
   */
  public function deleteDocuments(string $index_name, array $ids) {
    $index = $this->getIndex($index_name);
    if ($index) {
    if ($index = $this->getIndex($index_name)) {
      $index->deleteDocuments($ids);
    }
    return FALSE;
@@ -254,8 +246,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
        $index->deleteAllDocuments();
        $this->clearIdMapping($index_name);
        return TRUE;
      }
      catch (\Exception $e) {
      } catch (\Exception $e) {
        throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
      }

@@ -360,24 +351,23 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {

  /**
   * {@inheritdoc}
   * @throws \Drupal\search_api_meilisearch\Api\MeiliSearchApiException
   */
  public function setSettings(string $index_name, array $settings) {
    try {
      $index = $this->getIndex($index_name);
      if ($index) {
        return $index->updateSettings($settings);
      }
         return $index->updateFilterableAttributes($settings);
      }
    catch (\Exception $e) {
      throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
    }
    catch (NetworkException $e) {
    catch (\Exception | NetworkException $e) {
      throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
    }
  }

  /**
   * {@inheritdoc}
   * @throws \Drupal\search_api_meilisearch\Api\MeiliSearchApiException
   */
  public function getSettings(string $index_name) {
    $index = $this->getIndex($index_name);
@@ -405,7 +395,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  public function waitForUpdate(string $index_name, $update_id) {
    $index = $this->getIndex($index_name);
    if ($index) {
      $index->waitForPendingUpdate($update_id);
      $index->waitForTask($update_id);
      return TRUE;
    }
    return FALSE;
@@ -414,7 +404,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function getEnityId(string $index_name, string $id) {
  public function getEntityId(string $index_name, string $id) {
    $config = $this->configFactory->getEditable('search_api_meilisearch.settings');
    $meilisearch_id_mapping = $config->get('meilisearch_id_mappings') ?: [];
    $all_ids = $meilisearch_id_mapping[$index_name] ?: [];
@@ -457,8 +447,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
    if ($index) {
      try {
        return $index->resetSynonyms();
      }
      catch (HTTPRequestException $e) {
      } catch (ApiException $e) {
        throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
      }
    }
@@ -494,8 +483,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
    try {
      $this->connection();
      return TRUE;
    }
    catch (MeiliSearchApiException $e) {
    } catch (MeiliSearchApiException $e) {
      return FALSE;
    }
  }
@@ -506,8 +494,7 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
  public function keys() {
    try {
      return $this->connection()->getKeys();
    }
    catch (MeiliSearchApiException $e) {
    } catch (MeiliSearchApiException $e) {
      return FALSE;
    }
  }
+7 −8
Changes for src/Api/MeiliSearchApiServiceInterface.php: 7 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ interface MeiliSearchApiServiceInterface {
   * @param string $key
   *   The master key.
   */
  public function setMasterKey($key);
  public function setMasterKey(string $key);

  /**
   * Returns the URL of the server.
@@ -35,7 +35,7 @@ interface MeiliSearchApiServiceInterface {
   * Sets the servers url.
   *
   * @param string $url
   *   An URL of the server.
   *   A URL of the server.
   */
  public function setUrl(string $url);

@@ -76,7 +76,7 @@ interface MeiliSearchApiServiceInterface {
   *   The name of the index.
   *
   * @return array
   *   Returns the the index information.
   *   Returns the index information.
   *
   * @throws \Drupal\search_api_meilisearch\Api\MeiliSearchApiException
   *   Exception on an API call failure.
@@ -86,13 +86,12 @@ interface MeiliSearchApiServiceInterface {
  /**
   * Creates an index with attributes specified.
   *
   * @param string|array $attributes
   * @param array|string $attributes
   *   The name of the index or an array of attributes.
   *
   * @see https://github.com/meilisearch/meilisearch-php/
   *
   * @throws \Drupal\search_api_meilisearch\Api\MeiliSearchApiException
   *   Exception on an API call failure.
   * @see https://github.com/meilisearch/meilisearch-php/
   */
  public function createIndex($attributes);

@@ -181,7 +180,7 @@ interface MeiliSearchApiServiceInterface {
   * @throws \Drupal\search_api_meilisearch\Api\MeiliSearchApiException
   *   Exception on an API call failure.
   */
  public function deleteDocument(string $index, $id);
  public function deleteDocument(string $index, string $id);

  /**
   * Deletes multiple documents.
@@ -272,7 +271,7 @@ interface MeiliSearchApiServiceInterface {
   * @return string
   *   Drupal id.
   */
  public function getEnityId(string $index_name, string $id);
  public function getEntityId(string $index_name, string $id);

  /**
   * Gets the synonyms saved on the server.
Loading