Hosmel Quintana
Introduction
Installation
Configuration
Basic usage
Defining a Search
Fields and Columns
Operators and Values
Text and Wildcards
Free-Text Terms
Complements and Nullable Columns
Dates and Time Zones
JSON Columns
Relations
Aggregates
Scopes and Predicates
Full-Text Search
Directives and Sorting
Field Authorization
Validation Errors
Advanced usage
Custom Resolvers
Form Request Validation
View on GitHub

Configuration

Configure the validation error key and the query limits, and override them for a single search.

The install command publishes config/search-syntax-parser.php. You can leave the file unpublished to use its defaults.

OptionDefaultDescription
error_key'q'Attribute used for search validation errors. Form request rules use the attribute being validated.
max_clauses50Maximum number of user-supplied leaf clauses, including ignored clauses.
max_depth5Maximum nesting depth of groups and negations.
max_length1000Maximum number of Unicode characters in the raw input, including whitespace.

The limits must be positive integers. Field defaults do not count toward the clause or depth limits. Invalid configuration throws an exception; input that exceeds a limit produces a validation error.

Environment variables

The three query limits can be set through environment variables:

OptionEnvironment variable
max_clausesSEARCH_SYNTAX_PARSER_MAX_CLAUSES
max_depthSEARCH_SYNTAX_PARSER_MAX_DEPTH
max_lengthSEARCH_SYNTAX_PARSER_MAX_LENGTH

error_key has no environment variable. Edit it in config/search-syntax-parser.php.

Override one search

Call the corresponding method to change an option for one search:

php
use HosmelQ\SearchSyntaxParser\Laravel\Search;

$search = Search::make()
    ->errorKey('filters.q')
    ->maxClauses(30)
    ->maxDepth(4)
    ->maxLength(800);

You can also use these methods in the callback passed to whereSearch() or the form request rule.

See the core query limits for how clauses and depth are counted. Fields, term targets, sorting, and time zones belong to the search definition.

InstallationDefining a Search