spatie/elasticsearch-search-string-parser
Convert custom search strings like "foo bar status:active @john.doe" into ElasticSearch requests. Add directives via regex and the spatie/elasticsearch-query-builder, with grouping and autocomplete suggestions.
key:value operator syntax (the Slack/GitHub/Jira pattern users already know) or keep a single text box. This package prices that decision at roughly a sprint of directive authoring instead of a quarter of parser engineering — which changes the calculus from "not now" to "ship one directive and measure."group_by). That gives you a natural, per-ticket roadmap: "status filters" → "assignee mentions" → "saved sort" → "facets/aggregations," each independently shippable and reversible.status:active. That's a contained bet with no public-facing syntax contract to support or deprecate.spatie/elasticsearch-query-builder. Adopting it does not create meaningful lock-in — the directives you write are your own domain logic and survive a swap.Known costs to budget for, not just the code:
## Usage block is an unedited Spatie skeleton stub with an echoPhrase('Hello, Spatie!') example that has nothing to do with the package. Real learning requires reading the abstract directive classes in src/. Onboarding cost lands on your team, not the vendor.spatie/elasticsearch-query-builder and its clause semantics.status:"active, pending" and get surprising results. Plan for an error/empty-result experience.^2.0 = Elasticsearch 8 + the 8.x PHP client. ES7 clusters must stay on 1.x, and mismatches fail at the client layer with errors that look like parser bugs.Adopt when most of these are true:
elasticsearch/elasticsearch 8.x PHP client, on Laravel/PHP. (On ES7, the 1.x line exists but you're on a legacy branch — treat as a maintenance-only position.)key:value is a help, not a hurdle.status:, @assignee, company:) rather than a speculative syntax.Look elsewhere when any of these hold:
AND/OR/NOT, parenthetical grouping, wildcards, range operators. Regex-per-directive will fight you. Build or adopt an actual parser (or lean on Elasticsearch's own query_string/simple_query_string with carefully controlled inputs) instead.1.x for new work means starting on a branch that receives compatibility attention, not features.Recommended first commitment if you proceed: one internal screen, one base directive plus one pattern directive, shipping within a sprint. That surfaces the real questions — greedy regex interaction, empty-remainder behavior, hit hydration — at a fraction of the cost of discovering them behind a public feature.
To executives (30 seconds): Users of modern tools expect to type status:active @sarah and get exactly what they asked for. Today we can't offer that without building and maintaining a query parser, which is a quarter of engineering plus permanent upkeep. This package — MIT-licensed, from Spatie, a well-known PHP vendor — turns that into a per-sprint line item: one operator, one small class, one release. It's cheap to try, cheap to abandon, and the operator logic we write stays ours either way.
To engineering: It's a thin dispatcher, not a search engine. You declare regex-based directives; each match is applied through spatie/elasticsearch-query-builder and stripped from the string; the remainder goes to a single base directive. You get grouping and directive suggestions for free in a SearchResults object. Zero lock-in — our directives are plain PHP.
The three things to be honest about up front:
What it is not: it does not improve relevance. If the complaint driving this initiative is "the results are wrong," this is the wrong investment — that's index design and ranking tuning. If the complaint is "I can't narrow it down," this is the fastest path we have.
Ask: approve a one-sprint spike on an internal screen — one base directive, one pattern directive, measured against whether users actually type the operator. Success criteria: operator usage rate and a reduction in filter-clicks per search. If it doesn't earn the second directive, we stop with almost nothing sunk.
How can I help you explore Laravel packages today?