meilisearch / meilisearch-symfony

Seamless integration of Meilisearch into your Symfony project.
https://www.meilisearch.com
MIT License
125 stars 30 forks source link

Import of Mongo ODM entities fails #311

Closed Evoolo closed 11 months ago

Evoolo commented 11 months ago

Description I added some entities to my meilisearch config and then run php bin/console meilisearch:import. All MySQL entities are getting imported correctly. As soon as I reach the first mongo-odm entity, it fails with

In MeilisearchImportCommand.php line 115: Call to a member function getRepository() on null

While this package loads only the Doctrine\Persistence\ManagerRegistry wich can not be used for mongo-aod, I think this package is not compatible with the mongo-odm implementation.

Also when I try to persist a new entity, I get this error:

{ "code": 500, "message": "Meilisearch\Bundle\SearchableEntity::__construct(): Argument #3 ($entityMetadata) must be of type Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ODM\MongoDB\Mapping\ClassMetadata given, called in /home/vagrant/code/chgtwy_api/vendor/meilisearch/search-bundle/src/Services/MeilisearchService.php on line 318" }

Expected behavior creating a search index for all entities

Current behavior only creates an index for MySQL entities and throws an error on mongo-odm entities

In MeilisearchImportCommand.php line 115: Call to a member function getRepository() on null

Screenshots or Logs

// config/packages/meilisearch.yaml
meilisearch:
    url: '%env(MEILISEARCH_URL)%' # URL of the Meilisearch server (mandatory)
    api_key: '%env(MEILISEARCH_API_KEY)%' # API key to access the Meilisearch server (mandatory)
    prefix: '%env(MEILISEARCH_PREFIX)%'
    indices:
        - name: account
          class: App\Entity\Account\Account
          enable_serializer_groups: true
        - name: log_request
          class: App\Entity\LogRequest
          enable_serializer_groups: true
        - name: bsc_webhook
          class: App\Document\BinanceSmartChain\Webhook
          enable_serializer_groups: true
        - name: bsc_notification
          class: App\Document\BinanceSmartChain\Notification
          enable_serializer_groups: true
<?php

namespace App\Document\BinanceSmartChain;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

#[MongoDb\Document(db: 'IPN', collection: 'ipn_bsc_main_send', repositoryClass: \App\Repository\BinanceSmartChain\NotificationRepository::class)]
class Notification
{

    #[MongoDB\Id]
    protected $id;

    #[MongoDB\Field(type: 'string')]
    protected $txid;

    #[MongoDB\Field(type: 'string')]
    protected $webhook_id;

    #[MongoDB\Field(type: 'string')]
    protected $type;
...

Environment (please complete the following information):

norkunas commented 11 months ago

Hello,

ODM is currently not supported.

Sorry, that README states otherwise :disappointed: cc @brunoocasali why is that?

Evoolo commented 11 months ago

Okay thank you for the clarification. I will inspect all classes and do some PRs if I can manage to get it work.

norkunas commented 11 months ago

This needs more refactor than it looks - we need to support indexing any data, for example like requested in #302, then this will open door for simple integration with ODM

brunoocasali commented 11 months ago

Hi @norkunas, that statement in the README comes from the initial commit made by the original author of this library, but indeed I don't think we support ODM today. However, I can find some references to Mongo in the source code.

I will push a PR to remove that statement ;)