gbprod / algolia-specification
This library allows you to create Algolia queries using the Specification pattern
Installs: 13 821
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- algolia/algoliasearch-client-php: ^1.10
- gbprod/specification: ^2.0
Requires (Dev)
- phpunit/phpunit: ^6.0|^7.0
This package is auto-updated.
Last update: 2021-08-07 10:31:34 UTC
README
This library allows you to create Algolia queries using the specification pattern.
Usage
You can write specifications using gbprod/specification library.
Creates a algolia specification filter
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'; } }
Configure
$registry = new GBProd\AlgoliaSpecification\Registry(); $handler = new GBProd\AlgoliaSpecification\Handler($registry); $handler->registerFactory(IsAvailable::class, new IsAvailableFactory()); $handler->registerFactory(StockGreaterThan::class, new StockGreaterThanFactory());
Use it
$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]);
Requirements
- PHP >= 7.0
Installation
Using composer
composer require gbprod/algolia-specification