pgs-soft / elastic-om
Elasticsearch 对象映射器
v1.0.0
2016-12-06 12:32 UTC
Requires
- php: >=7
- doctrine/annotations: ^1
- elasticsearch/elasticsearch: ^2.2.2 | ^5
- zendframework/zend-hydrator: ^2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2
- kubawerlos/types-checker: ^1.0.1
- matthiasnoback/symfony-config-test: ^2
- phpunit/phpunit: ^5.4.3
- squizlabs/php_codesniffer: ^2.7
- symfony/dependency-injection: ^2.7 | ^3
- symfony/http-kernel: ^2.7 | ^3
- zendframework/zend-servicemanager: ^3
This package is auto-updated.
Last update: 2024-09-05 19:12:03 UTC
README
Elasticsearch 对象映射器。包括与 Symfony 2.7+ 和 Zend Framework 3 的集成。
安装
composer require pgs-soft/elastic-om
实体类型配置
Elasticsearch 类型是根据实体注解配置的,例如。
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);
可用的注解
Id
将类属性标记为用于唯一对象标识符。只能标记一个属性为 Id。
Field
指定要映射到 Elasticsearch 类型的属性。可用参数
- type - 属性的 Elasticsearch 映射类型。所有类型的列表可以在此找到:https://elastic.ac.cn/guide/en/elasticsearch/reference/current/mapping-types.html
- targetClass - 如果类型是 object 或 nested,则 targetClass 指定嵌套对象类
集成
Symfony
// app/AppKernel.php public function registerBundles() { $bundles = [ // ... new Pgs\ElasticOM\Bridge\Symfony\ElasticOMBundle(), // ... ]; }
# app/config.yml elastic_om: host: 'localhost' port: 9200 index: 'elastic_om'
$slug = $this->get('elastic_om.entity_repository_manager') ->getRepository(Author::class) ->update(new Author());
Zend Framework 3
// 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', ], // ... ];
贡献
欢迎在 GitHub 上提交错误报告和拉取请求:https://github.com/PGSSoft/ElasticOM。
关于
该项目由软件开发公司PGS Software维护。查看我们的其他开源项目或联系我们以开发您的产品。