Download the PHP package hosmelq/search-syntax-parser without Composer
On this page you can find all versions of the php package hosmelq/search-syntax-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hosmelq/search-syntax-parser
More information about hosmelq/search-syntax-parser
Files in hosmelq/search-syntax-parser
Package search-syntax-parser
Short Description Parse search queries into structured data with field searches, boolean logic, ranges, lists, and adapters.
License MIT
Informations about the package search-syntax-parser
Search Syntax Parser
Parse search queries into structured data with support for field searches, boolean logic, range comparisons, and multiple output formats.
Introduction
Use a concise, expressive query language to build structured queries. It supports field-specific searches, boolean operators, ranges, existence checks, and multi-value lists, and outputs to multiple formats via adapters.
It returns a normalized PHP array describing the query.
Requirements
- PHP 8.4+
The package is framework-independent and can be installed alongside Laravel 12 and 13.
Installation & setup
Install the package via composer:
Basic usage
Getting started
Create a parser from a query string and build it using the default array adapter:
Default adapter (array)
When no adapter is provided, build() uses the array adapter and returns a structured PHP array.
Query types
Connectives (AND/OR)
Combine multiple terms with logical operators. When no connective is specified, AND is implied.
Comparators
Use field comparison operators to define the relationship between a field and its value:
Comma-separated values
Use multi-value field searches as syntactic sugar for OR operations:
Exists queries
Search for documents with non-null values in specified fields using wildcard syntax:
Range queries
Search within value ranges using boundary operators:
Terms
Search using basic terms that match default searchable fields:
Modifiers (NOT)
Negate terms or subqueries using - or NOT:
Field validation
Restrict which fields can be used and validate their values using AllowedField helpers:
You can also map external field names to internal ones:
Array item validation (each and at)
For array fields, use each() to validate every item and at(index) to validate specific positions.
Per‑item rules with each():
Index‑specific rules with at() (tuple‑like arrays):
Custom adapters
Create custom output formats by implementing the adapter interface:
Error handling
Handle parsing errors with ParseException:
Testing
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Credits
- Hosmel Quintana
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of search-syntax-parser with dependencies
archtechx/enums Version ^1.1
brick/math Version ^0.14.2 || ^0.15 || ^0.16 || ^0.17 || ^0.18 || ^0.19 || ^0.20 || ^1.0
doctrine/lexer Version ^3.0
thecodingmachine/safe Version ^3.4