pallares/query-syntax

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.0.1) of this package.

Maintainers

Package info

github.com/skyrpex/query-syntax-php

pkg:composer/pallares/query-syntax

Statistics

Installs: 3 003

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 3

1.0.1 2017-07-09 22:15 UTC

This package is auto-updated.

Last update: 2025-08-05 06:32:48 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'],
            ],
        ]
    ],
];