galexth / elasticsearch-querybuilder
elasticsearch querybuilder
v1.2.8
2019-09-30 16:30 UTC
Requires
- php: >=7.1.3|^7.2
- illuminate/support: ^5.6|^6.0
- ruflin/elastica: ^6.0
Requires (Dev)
- fzaninotto/faker: ~1.6
- illuminate/validation: ^5.6|^6.0
- kint-php/kint: ^2.1
- mockery/mockery: ~1.0
- monolog/monolog: ^1.22
- phpunit/phpunit: ~7.0
README
Elastica query builder for laravel.
Rules
Each rules have to implement \Galexth\QueryBuilder\Rule interface with pattern() array:
class MyRule implements Rule { public function patterns(): array { return [ [ 'name' => 'location.country', // name of the field in the query (@location.country has ....) 'query_type' => 'terms', // query type (terms, term, match, multi_match, etc...) 'fields' => ['locations.country'], // fields to search in // nested if necessary 'nested' => [ 'path' => 'locations' ], 'type' => 'text', // value type (text, integer, date), text is only supported by now ], // custom handler [ 'name' => 'persona', 'query_type' => 'custom', 'fields' => ['persona_id'], 'type' => 'text', 'callback' => function ($values) { $bool = new BoolQuery(); return $bool->addFilter(new Terms('asd', (array) $values)); } ], // using a regular expressions [ 'name' => 'rank\.(?<sub_field>[\w-_]+)$', 'expression' => true, 'query_type' => 'terms', 'fields' => ['ranks.{sub_field}'], 'type' => 'text', ], ... ]; } }
Query
Use queries like:
$query = '@name is Prof. Johan Schoen and @industry is Network Security Hardware & Software'; $query = '@name is "John" and @industry is \'Medicine\' or (@industry is Oil and @name is Chris) or @name is Jesus'; $query = '@revenue gte 123 and @revenue lt 523'; ...
More examples could be found in tests.
$builder = new Builder(new MyRule); $bool = $builder->build($query); // BoolQuery