gbprod / elastica-specification
此软件包已被废弃,不再维护。未建议替代软件包。
此库允许您使用规范模式创建Elastica查询
v2.1.0
2018-02-08 06:45 UTC
Requires
- php: ^7.0
- gbprod/specification: ^2.0
- ruflin/elastica: ^5.0|^6.0
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2021-08-07 10:30:25 UTC
README
此库允许您使用规范模式创建Elastica查询。
使用方法
您可以使用gbprod/specification库编写规范。
创建Elastica规范过滤器
namespace GBProd\Acme\Elastica\SpecificationFactory; use GBProd\ElasticaSpecification\QueryFactory\Factory; use GBProd\Specification\Specification; use Elastica\QueryBuilder; class IsAvailableFactory implements Factory { public function create(Specification $spec, QueryBuilder $qb) { return $qb->query()->bool() ->addMust( $qb->query()->term(['available' => "0"]), ) ; } }
配置
$registry = new GBProd\ElasticaSpecification\Registry(); $qb = new \Elastica\QueryBuilder(); $handler = new GBProd\ElasticaSpecification\Handler($registry, $qb); $handler->registerFactory(IsAvailable::class, new IsAvailableFactory()); $handler->registerFactory(StockGreaterThan::class, new StockGreaterThanFactory());
使用它
$available = new IsAvailable(); $hightStock = new StockGreaterThan(4); $availableWithLowStock = $available ->andX( $hightStock->not() ) ; $type = $this->elasticaClient ->getIndex('my_index') ->getType('my_type') ; $query = $handler->handle($availableWithLowStock) $results = $type->search($query);
要求
- PHP 7.0+
安装
使用composer
composer require gbprod/elastica-specification