meilisearch / meilisearch-symfony

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

meili:import is not picking up configuration from meilisearch.yaml #227

Closed Seesicht-IT closed 1 year ago

Seesicht-IT commented 1 year ago

Description I try to attach my Symfony 5.4.12 project to Meilisearch, but I cannot import data into the index. I installed the bundle successfully. This is how my composer.json file looks like:

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=8.1",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-soap": "*",
        "beberlei/doctrineextensions": "^1.3",
        "composer/package-versions-deprecated": "1.11.99.4",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.5",
        "doctrine/doctrine-migrations-bundle": "^3.2",
        "doctrine/orm": "^2.10",
        "league/csv": "^9.8",
        "meilisearch/search-bundle": "^0.10.1",
        "mpdf/mpdf": "^8.0",
        "nelmio/api-doc-bundle": "^4.9",
        "nyholm/psr7": "^1.5",
        "phpdocumentor/reflection-docblock": "^5.2",
        "phpoffice/phpspreadsheet": "^1.21",
        "sensio/framework-extra-bundle": "^6.2",
        "symfony/apache-pack": "^1.0",
        "symfony/asset": "5.4.*",
        "symfony/console": "5.4.*",
        "symfony/dotenv": "5.4.*",
        "symfony/filesystem": "5.4.*",
        "symfony/flex": "^1.3.1",
        "symfony/framework-bundle": "5.4.*",
        "symfony/http-client": "5.4.*",
        "symfony/mailer": "5.4.*",
        "symfony/monolog-bundle": "^3.7",
        "symfony/password-hasher": "5.4.*",
        "symfony/property-access": "5.4.*",
        "symfony/property-info": "5.4.*",
        "symfony/proxy-manager-bridge": "5.4.*",
        "symfony/runtime": "5.4.*",
        "symfony/security-bundle": "5.4.*",
        "symfony/serializer": "5.4.*",
        "symfony/twig-bundle": "5.4.*",
        "symfony/yaml": "5.4.*",
        "teamtnt/tntsearch": "^2.9",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "escapestudios/symfony2-coding-standard": "^3.12",
        "rector/rector": "^0.14.2",
        "squizlabs/php_codesniffer": "3.*",
        "symfony/maker-bundle": "^1.34"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true,
        "allow-plugins": {
            "symfony/flex": true,
            "symfony/runtime": true,
            "php-http/discovery": true
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.4.*"
        }
    }
}

The MeilisearchBundle was also automatically added to the bundles.php of Symfony.

I then created a meilisearch.yaml file in the config/packages folder. The documentation sometimes uses meilisearch.yaml and sometimes meili_search.yaml. So, I am not certain, what is the right name.

The content of the meilisearch.yaml file looks like this:

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)
  nbResults: 22                          # Retrieve fewer results on search (default: 20)
  doctrineSubscribedEvents: []           # disable doctrine events (turn off realtime sync)
  batchSize: 555                         # calls to Meilisearch to index or remove data are batched per items (default: 500)
  indices:
    - name: articles
      class: App\Entity\InterfaceArticle
      enable_serializer_groups: true

I also added the env-variable to my .env.local file like this:

## Milisearch settings
MEILISEARCH_URL="http://127.0.0.1:7700"
MEILISEARCH_API_KEY="X7od_eJ-mRBs_bZjxARzf_oJ"

Finally I added the groups-attributes to my InterfaceArticle class:

namespace App\Entity;

use App\Repository\InterfaceArticleRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

#[ORM\Table]
#[ORM\Index(name: 'INDEX_SKUID_SEARCH', columns: ['sku_id', 'manufacturer_number', 'manufacturer_item_number', 'gtin'])]
#[ORM\Entity(repositoryClass: InterfaceArticleRepository::class)]
class InterfaceArticle
{
    #[ORM\Id]
    #[ORM\Column(type: 'string', length: 20, unique: true)]
    #[Groups(['searchable'])]
    private $gtin;

    #[ORM\Column(type: 'bigint', nullable: true)]
    #[Groups(['searchable'])]
    private $manufacturerNumber;

    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Groups(['searchable'])]
    private $manufacturerName;

    #[ORM\Column(type: 'string', length: 255)]
    #[Groups(['searchable'])]
    private $manufacturerItemNumber;

    #[ORM\Column(type: 'string', length: 255)]
    #[Groups(['searchable'])]
    private $itemDescription;
...

When I now run the command php bin/console meili:import I get the message:

No indices specified. Please either specify indices using the cli option or YAML configuration. Done!

When I run the command php bin/console meili:import --indices=articles then I get this message, but nothing happens:

Done!

I also see in the console of the Docker container that nothing is happening there when I run the command.

I looked into the file MeilisearchImportCommand.php and added a dd($config); in line 72: image When I run the command again, the output is like this: image So, it is not picking up the configuration from my meilisearch.yaml file at all.

What am I doing wrong? Any advice is appreciated.

Expected behavior The Meilisearch importer picks up the configuration from the yaml file and process the import properly.

Current behavior The import is not running at all.

Environment (please complete the following information):

Seesicht-IT commented 1 year ago

I just ran another php bin/console cache:clear after writing this ticket, and now it is working perfectly. Sorry for the trouble!