弹性搜索的自定义提供程序

时间:2014-06-20 12:13:45

标签: symfony search elasticsearch provider

我正在尝试为我的实体Deal创建自定义提供程序。首先,这是我的 config.yml ,我确定了我的实体:

Deal:
    persistence:
        driver: orm
        model:  eDeally\CoreBundle\Entity\Deal
        provider: 
        listener: ~
        finder: ~

我也在" provider.xml"

中定义它
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>

    <!-- Search providers -->
    <parameter key="custom.search.provider.deal.class">eDeally\CoreBundle\Provider\DealProvider</parameter>

</parameters>

<services>

    <!-- Search providers -->
    <service id="custom.search.provider.deal" class="%custom.search.provider.deal.class%">
        <tag name="fos_elastica.provider" index="afsy" type="Deal" />
        <argument type="service" id="fos_elastica.object_persister.afsy.deal" />
        <argument type="service" id="fos_elastica.client.default" />
        <argument type="service" id="doctrine" />
    </service>

</services>

最后,我有文件&#34; DealProvider.php&#34;

类DealProvider实现ProviderInterface {

private $objectPersister;
private $client;
private $doctrine;

public function __construct(ObjectPersisterInterface $objectPersister, Client $client, ManagerRegistry $doctrine)
{
    $this->objectPersister  = $objectPersister;
    $this->client           = $client;
    $this->doctrine         = $doctrine;
}

/**
 * Insert the repository objects in the type index
 *
 * @param \Closure $loggerClosure
 * @param array    $options
 */
public function populate(\Closure $loggerClosure = null, array $options = array())
{
            echo "heyyyyy";
            exit(1);
    // Default values
    $lastid     = isset($options['offset']) ? intval($options['offset']) : 0;
    $batchSize  = isset($options['batch-size']) ? intval($options['batch-size']) : 100;

    // Create query
    $em     = $this->doctrine->getManager();
    $repository = $em->getRepository("eDeallyCoreBundle:Deal");
    $qb = $repository->createQueryBuilder("deal")
        ->select("deal");
            $qb->andWhere('deal.deleted = :false');
            $qb->andwhere('deal.finished = :false');
            $qb->andwhere('deal.stopped = :false');
            $qb->andWhere('deal.start_date <= :date');
            $qb->andWhere('deal.end_date >= :date');


    // Memory managment
    $em->getConnection()->getConfiguration()->setSQLLogger(null);
    $this->client->setLogger(new \Psr\Log\NullLogger());

    // Batch items
    do {

        // Reset start time
        if ($loggerClosure) {
            $stepStartTime = microtime(true);
        }

        // Retrieve data
                    $date = new \DateTime;
                    $objects = $qb->setParameter('date',$date->format("Y-m-d"))
                                  ->setParameter('false',0) 
                                  ->getQuery()
                                  ->getResult();

        if (count($objects) === 0) {
            break;
        }

        // Convert and save objects
        $this->objectPersister->insertMany($objects);

        // Log
        if ($loggerClosure) {
            $objectsPerSecond = count($objects) / (microtime(true) - $stepStartTime);
            $loggerClosure(sprintf('lastid %s, %d objects/s %s', $lastid, $objectsPerSecond, $this->getMemoryUsage()));
        }

        // Save last id for query
        $lastid = end($objects)->getId();

        // Memory managment
        $em->clear();
        unset($objects);

    } while (true);
}

/**
 * Get string with RAM usage information (current and peak)
 *
 * @return string
 */
protected function getMemoryUsage()
{
    $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo
    $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo
    $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)';

    return $message;
}

}

但是当我执行“fos:elastica:populate&#39;”时似乎没有任何改变。我放了一个echo "hey"exit(1)来尝试改变但是没有。

我必须在yml中配置一些东西才能启用提供程序? 谢谢:))

对不起我的英文:/我很好吗

0 个答案:

没有答案