PHP code example of pgs-soft / elastic-om

1. Go to this page and download the library: Download pgs-soft/elastic-om library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pgs-soft / elastic-om example snippets


    use Pgs\ElasticOM\Annotation as ODM;

    class Book
    {
        /**
         * @var string
         * @ODM\Id
         * @ODM\Field(type="string")
         */
        private $id;

        /**
         * @var Author
         * @ODM\Field(type="nested", targetClass="AppBundle\Entity\Author")
         */
        private $author;

        /**
         * @var string
         * @ODM\Field(type="string")
         */
        private $title;

        // ...
    }

    use Pgs\ElasticOM\ElasticApi\ApiServiceFactory;

    $api = ApiServiceFactory::create('localhost', '9200', 'elastic_om');

    // creating index 'elastic_om'
    $api->createIndex();

    // creating type Book
    $api->createType(Book::class);

    // updating type Book
    $api->updateType(Book::class);

    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            // ...
            new Pgs\ElasticOM\Bridge\Symfony\ElasticOMBundle(),
            // ...
        ];
    }

    $slug = $this->get('elastic_om.entity_repository_manager')
        ->getRepository(Author::class)
        ->update(new Author());

    // config/modules.config.php
    return [
        // ...
        'Pgs\ElasticOM\Bridge\ZF3',
    ];

    // module/Application/config/module.config.php
    'controllers' => [
        'factories' => [
            ExampleController::class => function ($em) {
                return new ExampleController($em->get('elastic_om.entity_repository_manager'));
            },
        ],
    ],

    // config/module.config.php
    return [
        // ...
        'elastic_om' => [
            'host' => 'localhost',
            'port' => '9200',
            'index' => 'elastic_om',
        ],
        // ...
    ];