monsieurbiz / sylius-search-plugin
一个用于Sylius的基于Elasticsearch的搜索插件。
Requires
- php: ^8.0
- babdev/pagerfanta-bundle: ^2.5 || ^3.0
- jacquesbh/eater: ^2.0
- jane-php/automapper-bundle: ^7.1
- jolicode/elastically: ^1.4.0
- monsieurbiz/sylius-settings-plugin: ^1.2
- sylius/sylius: >=1.11 <1.14
- symfony/messenger: ^4.4 || ^5.2 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.16
- phpmd/phpmd: ^2.15
- phpspec/phpspec: ^7.0
- phpstan/phpstan: ^1.8.4
- phpstan/phpstan-doctrine: ^1.3.2
- phpstan/phpstan-webmozart-assert: ^1.1
- phpunit/phpunit: ^10.5
- dev-master / 2.2.x-dev
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-RC.23
- v2.0.0-RC.22
- v2.0.0-RC.21
- v2.0.0-RC.20
- v2.0.0-RC.19
- v2.0.0-RC.18
- v2.0.0-RC.17
- v2.0.0-RC.16
- v2.0.0-RC.15
- v2.0.0-RC.14
- v2.0.0-RC.13
- v2.0.0-RC.12
- v2.0.0-RC.11
- v2.0.0-RC.10
- v2.0.0-RC.9
- v2.0.0-RC.8
- v2.0.0-RC.7
- v2.0.0-RC.6
- v2.0.0-RC.5
- v2.0.0-RC.4
- v2.0.0-RC.3
- v2.0.0-RC.2
- v2.0.0-RC.1
- 1.x-dev
- v1.0.0-RC.10
- v1.0.0-RC.9
- v1.0.0-RC.8
- v1.0.0-RC.7
- v1.0.0-RC.6
- v1.0.0-RC.5
- v1.0.0-RC.4
- v1.0.0-RC.3
- v1.0.0-RC.2
- v1.0.0-RC.1
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
This package is auto-updated.
Last update: 2024-09-23 07:54:59 UTC
README
搜索
一个使用Elastically和Jane的Sylius搜索插件。
兼容性
安装
如果您想使用我们的配方,可以通过运行以下命令来配置您的composer.json:
composer config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]'
这是使用jane-php/automapper的最后一个版本,它需要nikic/php-parser="^4.0"
。下一个版本将使用jolicode/automapper,它与nikic/php-parser="^5.0"
兼容。
composer require --no-progress --no-interaction nikic/php-parser="^4.0"
composer require monsieurbiz/sylius-search-plugin
如果您使用Symfony Flex,配方将自动执行一些操作。
对于不带flex的安装,请遵循以下附加步骤:
将您的config/bundles.php
文件更改为添加以下行以声明插件:
<?php return [ //.. MonsieurBiz\SyliusSearchPlugin\MonsieurBizSyliusSearchPlugin::class => ['all' => true], Jane\Bundle\AutoMapperBundle\JaneAutoMapperBundle::class => ['all' => true], ];
在config/packages/monsieurbiz_sylius_search_plugin.yaml
中创建配置文件
imports: - { resource: "@MonsieurBizSyliusSearchPlugin/Resources/config/config.yaml" }
在config/routes/monsieurbiz_sylius_search_plugin.yaml
中创建路由配置文件
monsieurbiz_search_plugin: resource: "@MonsieurBizSyliusSearchPlugin/Resources/config/routing.yaml"
复制覆盖模板
cp -Rv vendor/monsieurbiz/sylius-search-plugin/src/Resources/templates/* templates/
最后,通过在文件的末尾添加以下行来在您的.env文件中配置插件:
###> MonsieurBizSearchPlugin ###
MONSIEURBIZ_SEARCHPLUGIN_MESSENGER_TRANSPORT_DSN=doctrine://default
MONSIEURBIZ_SEARCHPLUGIN_ES_HOST=${ELASTICSEARCH_HOST:-localhost}
MONSIEURBIZ_SEARCHPLUGIN_ES_PORT=${ELASTICSEARCH_PORT:-9200}
MONSIEURBIZ_SEARCHPLUGIN_ES_URL=http://${MONSIEURBIZ_SEARCHPLUGIN_ES_HOST}:${MONSIEURBIZ_SEARCHPLUGIN_ES_PORT}/
###< MonsieurBizSearchPlugin ###
-
安装Elasticsearch 💪。请参阅以下部分的基础设施。
-
您的
ProductAttribute
和ProductOption
实体需要实现MonsieurBiz\SyliusSearchPlugin\Entity\Product\SearchableInterface
接口,并使用MonsieurBiz\SyliusSearchPlugin\Model\Product\SearchableTrait
特性。以下是一个使用ProductAttribute
的示例:
namespace App\Entity\Product; use Doctrine\ORM\Mapping as ORM; +use MonsieurBiz\SyliusSearchPlugin\Entity\Product\SearchableInterface; +use MonsieurBiz\SyliusSearchPlugin\Model\Product\SearchableTrait; use Sylius\Component\Attribute\Model\AttributeTranslationInterface; use Sylius\Component\Product\Model\ProductAttribute as BaseProductAttribute; /** * @ORM\Entity * @ORM\Table(name="sylius_product_attribute") */ #[ORM\Entity] #[ORM\Table(name: 'sylius_product_attribute')] -class ProductAttribute extends BaseProductAttribute +class ProductAttribute extends BaseProductAttribute implements SearchableInterface { + use SearchableTrait; protected function createTranslation(): AttributeTranslationInterface { return new ProductAttributeTranslation();
-
您需要运行doctrine迁移的diff:
console doctrine:migrations:diff
。不要忘记运行它!(console doctrine:migrations:migrate
) -
运行填充命令。
文档
基础设施
该插件是为Elasticsearch 7.16.x版本开发的。您需要安装analysis-icu和analysis-phonetic elasticsearch插件。
其他信息
Jane
我们使用Jane来创建DTO(数据传输对象)。
生成的类位于generated
文件夹中。
Jane配置和JSON Schema位于src/Resources/config/jane
文件夹中。
在插件开发期间重新构建生成的类,我们使用
symfony php vendor/bin/jane generate --config-file=src/Resources/config/jane/jane-configuration.php
Elastically
Elastically客户端配置在src/Resources/config/services.yaml
文件中。
您可以在.env文件中自定义它,或者在config/services.yaml
中。
分析器和YAML映射位于src/Resources/config/elasticsearch
文件夹中。