webfactory/content-mapping-destinationadapter-solarium-bundle

1.9.1 2024-09-04 15:30 UTC

This package is auto-updated.

Last update: 2024-09-04 15:31:10 UTC


README

这是一个用于 webfactory/content-mapping-destinationadapter-solarium 的 Symfony 扩展包,它通过简单的配置、服务和控制台命令,简化了您的同步工作。

安装

使用 composer 安装此包

composer require webfactory/content-mapping-destinationadapter-solarium-bundle

并在您的应用程序内核中启用两个扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    // ...
    $bundles[] = new Webfactory\ContentMappingDestinationAdapterSolariumBundle\WebfactoryContentMappingDestinationAdapterSolariumBundle();
    $bundles[] = new Nelmio\SolariumBundle\NelmioSolariumBundle();
    // ...
}

最后,配置 Solarium 客户端的端点(目前仅支持默认端点和默认客户端)

// app/config.yml

nelmio_solarium:
    endpoints:
        default:
            dsn: http://localhost:8983/solr/your-core

# for SolariumBundle 3.x (beta)            
nelmio_solarium:
    endpoints:
        default:
            host: localhost
            port: 8983
            core: your-core

使用方法

该扩展包提供了一个名为 contentmapping.destinationadapter.solarium 的服务,您可以使用它来在 webfactory/content-mapping 小型框架中定义同步服务

<!-- Resources/config/services.xml -->

<!-- Synchronizer for MyEntity --->
<service class="Webfactory\ContentMapping\Synchronizer">
    <!-- SourceAdapter -->
    <argument type="service">
        <service class="Webfactory\ContentMapping\SourceAdapter\Doctrine\GenericDoctrineSourceAdapter">
            <!-- Doctrine Repository -->
            <argument type="service">
                <service class="MyVendor\MyBundle\Entity\MyEntityRepository" factory-service="doctrine.orm.entity_manager" factory-method="getRepository">
                    <argument>MyVendorMyEntityBundle:MyEntity</argument>
                </service>
            </argument>
            <!-- Name of the repository method to query -->
            <argument type="string">findForSolrIndex</argument>
        </service>
    </argument>

    <!-- Mapper -->
    <argument type="service">
        <service class="MyVendor\MyBundle\ContentMapping\MyEntityMapper" />
    </argument>

    <!-- DestinationAdapter -->
    <argument type="service" id="contentmapping.destinationadapter.solarium"/>

    <!-- PSR3-logger -->
    <argument type="service" id="logger" />
    <tag name="monolog.logger" channel="solr" />
    
    <!-- Tag to mark the service as a Synchronizer -->
    <tag name="contentmapping.synchronizer" objectclass="\JugendFuerEuropa\Bundle\JugendInAktionBundle\Entity\Mitarbeiter" />
</service>

<!-- other Synchronizers --->

此外,该扩展包还提供了一个控制台命令,用于从 Solr 索引中删除与查询匹配的数据

app/bin content-mapping:solarium:delete-from-index [query=*:*]

致谢、版权和许可

该项目始于德国波恩的 webfactory GmbH。

版权所有 2015-2022 webfactory GmbH,波恩。代码在 MIT 许可证 下发布。