gbprod/algolia-specification

此包已被废弃且不再维护。未建议替代包。

此库允许您使用规范模式创建 Algolia 查询。

v2.1.0 2018-02-26 09:35 UTC

This package is auto-updated.

Last update: 2021-08-07 10:31:34 UTC


README

Build Status codecov Scrutinizer Code Quality Dependency Status

Latest Stable Version Total Downloads Latest Unstable Version License

此库允许您使用 Algolia 查询,并使用 规范模式

用法

您可以使用 gbprod/specification 库编写规范。

创建 Algolia 规范过滤器

@see Algolia 文档

namespace GBProd\Acme\Algolia\SpecificationFactory;

use GBProd\AlgoliaSpecification\QueryFactory\Factory;
use GBProd\Specification\Specification;

class IsAvailableFactory implements Factory
{
    public function create(Specification $spec)
    {
        return 'available=1';
    }
}

配置

$registry = new GBProd\AlgoliaSpecification\Registry();

$handler = new GBProd\AlgoliaSpecification\Handler($registry);
$handler->registerFactory(IsAvailable::class, new IsAvailableFactory());
$handler->registerFactory(StockGreaterThan::class, new StockGreaterThanFactory());

使用

$available = new IsAvailable();
$hightStock = new StockGreaterThan(4);

$availableWithLowStock = $available
    ->andX(
        $hightStock->not()
    )
;
$client = new \AlgoliaSearch\Client('YourApplicationID', 'YourAPIKey');
$index = $client->initIndex('index_name');

$query = $handler->handle($availableWithLowStock)

$results = $type->search(['filters' => $query]);

需求

  • PHP >= 7.0

安装

使用 composer

composer require gbprod/algolia-specification