Skip to content

Add SearchBuilder JSON serialization support - #682

Open
Toflar wants to merge 2 commits into
PHP-CMSIG:0.12from
Toflar:feature/serializable-search-builder
Open

Add SearchBuilder JSON serialization support#682
Toflar wants to merge 2 commits into
PHP-CMSIG:0.12from
Toflar:feature/serializable-search-builder

Conversation

@Toflar

@Toflar Toflar commented Apr 23, 2026

Copy link
Copy Markdown
Member

Search UIs often need to preserve and share a complete search state: query text, filters, sorting, pagination, highlighting, distinct handling, and facets. Passing each part through separate request parameters makes controller and API code grow quickly, and it becomes harder to hand the same search state between pages, links, and clients.

This adds a JSON representation for SearchBuilder, so applications can pass the complete search state as one value, for example ?search=<json>.

The index remains internal and is intentionally not part of the serialized payload. Public endpoints can also provide a SearchBuilderValidation instance when reading external JSON, allowing them to expose only a safe subset of internally available filters, facets, sorting, and other search features.

See documentation on how this can be used 😎

@Toflar Toflar self-assigned this Apr 23, 2026
@Toflar Toflar added documentation Improvements or additions to documentation features New feature or request SEAL Core Seal Core related issue DX Improves the developer experience labels Apr 23, 2026
@Toflar
Toflar marked this pull request as ready for review April 23, 2026 13:12

@alexander-schranz alexander-schranz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting, I understand the usecase, it goes into the same direction I had in mind with support for Galach / #462.

In my opinion Condition, Facet, .... class should be kept as they were before, they should know nothing about this whole mechanic same for the SearchBuilder. I totally aware of the disadvantage of that but want keep core things as small as possible. Own functionality should live in its own place, I even has already some parts in mind to be split out.

For me this is an own factory service which single responsibility is add filter, sortbys, ... by the given array and config:

Something like:

$jsonSearchBuilderFactory = new JsonSearchBuilderFactory($this->engine);

$searchBuilder = $jsonSearchBuilderFactory->build(
   'blog',
   $jsonSearchBuilderConfig,
   $array,
);

I really like the concept that every Builder has its SearchBuilderValidation, not sure about the name so I would go with JsonSearchBuilderConfig, but it should not be optional as it could else open unexpected security issues, specially with the extendability of Indexes SEAL provides.

Another question is it really should concentrate on json or better on array, which example the output of Symfony Forms or other similar libraries can produce.

So maybe ArraySearchBuilderFactory is the better name here,

I think the feature could be implemented the way it lives only in 2 classes and not have need change any other classes:

  • ArraySearchBuilderFactory
  • SearchBuilderFactoryConfig

inside a SearchBuilderFactory namespace. The SearchBuilderFactoryConfig is something which may can in future also be used to create a GalachSearchBuilderFactory or any other future query language translator can use.

Comment thread packages/seal/src/Search/Condition/AbstractGroupCondition.php Outdated
@Toflar

Toflar commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

A bit more like this then? 😊

@alexander-schranz

alexander-schranz commented Apr 27, 2026

Copy link
Copy Markdown
Member

Did not do yet do a deep review but yes :) 👍

@Toflar
Toflar force-pushed the feature/serializable-search-builder branch from c54052a to e7b298b Compare April 27, 2026 13:34
@Toflar
Toflar changed the base branch from 0.13 to 0.12 April 27, 2026 13:34
@Toflar
Toflar force-pushed the feature/serializable-search-builder branch from e7b298b to be5f48c Compare April 27, 2026 13:39
@alexander-schranz alexander-schranz added the Hold back Features Features currently on hold due to higher roadmap priorities before deeper discussion. label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation DX Improves the developer experience features New feature or request Hold back Features Features currently on hold due to higher roadmap priorities before deeper discussion. SEAL Core Seal Core related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants