pallares/query-syntax

There is no license information available for the latest version (1.0.1) of this package.

1.0.1 2017-07-09 22:15 UTC

README

This package allows you to parse Algolia-like queries into sort of a AST.

Installation

composer require pallares/query-syntax

Usage example

$query = 'director:"Steven Spielberg" AND (category:"sci-fi" OR category:terror)';

$lexer = new Pallares\QuerySyntax\Lexer($query);

$ast = (new Pallares\QuerySyntax\Parser)->parse($lexer);

The AST looks like this:

$ast === [
    'operator' => 'and',
    'children' => [
        ['operator' => 'comparison', 'key' => 'director', 'value' => 'Steven Spielberg'],
        [
            'operator' => 'or',
            'children' => [
                ['operator' => 'comparison', 'key' => 'category', 'value' => 'sci-fi'],
                ['operator' => 'comparison', 'key' => 'category', 'value' => 'terror'],
            ],
        ]
    ],
];