rollerworks / search-dev
RollerworksSearch monolith development (use separate packages instead)
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 109
Watchers: 6
Forks: 17
Open Issues: 11
Type:project
Requires
- php: >=8.1
- nesbot/carbon: ^2.38 || ^3.0
- psr/container: ^1.0 || ^2.0
- symfony/intl: ^6.4 || ^7.0
- symfony/options-resolver: ^6.4 || ^7.0
- symfony/property-access: ^6.4 || ^7.0
- symfony/string: ^6.4 || ^7.0
- symfony/translation-contracts: ^3.4
Requires (Dev)
- api-platform/core: ^3.2
- doctrine/doctrine-bundle: ^1.9.1 || ^2.2.3
- doctrine/orm: ^2.7.3
- jangregor/phpstan-prophecy: ^1.0.0
- matthiasnoback/symfony-dependency-injection-test: ^4.1.1 || ^5.1
- moneyphp/money: ^3.2.0 || ^4.0
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5.7
- psr/simple-cache: ^1.0||^2.0.0||^3.0.0
- rollerscapes/standards: ^0.2.4
- ruflin/elastica: ^7.0
- symfony/asset: ^6.4 || ^7.0
- symfony/browser-kit: ^6.4 || ^7.0
- symfony/dom-crawler: ^6.4 || ^7.0
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/http-foundation: ^6.4 || ^7.0
- symfony/phpunit-bridge: ^6.4 || ^7.0
- symfony/routing: ^6.4 || ^7.0
- symfony/templating: ^6.4 || ^7.0
- symfony/translation: ^6.4 || ^7.0
- symfony/twig-bundle: ^6.4 || ^7.0
- symfony/validator: ^6.4 || ^7.0
- symfony/var-dumper: ^6.4 || ^7.0
Suggests
- moneyphp/money: To use the MoneyType
Conflicts
- moneyphp/money: <3.2.0
Replaces
- rollerworks/search: v2.0.0-BETA6
- rollerworks/search-api-platform: v2.0.0-BETA6
- rollerworks/search-bundle: v2.0.0-BETA6
- rollerworks/search-doctrine-dbal: v2.0.0-BETA6
- rollerworks/search-doctrine-orm: v2.0.0-BETA6
- rollerworks/search-elasticsearch: v2.0.0-BETA6
- rollerworks/search-symfony-validator: v2.0.0-BETA6
- dev-main / 2.0.x-dev
- v2.0.0-BETA6
- v2.0.0-BETA5
- v2.0.0-BETA4
- v2.0.0-BETA3
- v2.0.0-BETA2
- v2.0.0-BETA1
- v2.0.0-ALPHA23
- v2.0.0-ALPHA22
- v2.0.0-ALPHA21
- v2.0.0-ALPHA20
- v2.0.0-ALPHA19
- v2.0.0-ALPHA18
- v2.0.0-ALPHA17
- v2.0.0-ALPHA16
- v2.0.0-ALPHA15
- v2.0.0-ALPHA14
- v2.0.0-ALPHA13
- v2.0.0-ALPHA12
- v2.0.0-ALPHA11
- v2.0.0-ALPHA10
- v2.0.0-ALPHA9
- v2.0.0-ALPHA8
- v2.0.0-ALPHA7
- v2.0.0-ALPHA6
- v2.0.0-ALPHA5
- v2.0.0-ALPHA4
- v2.0.0-ALPHA3
- v2.0.0-ALPHA2
- v2.0.0-ALPHA1
- 1.x-dev
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v1.0.0-beta8
- v1.0.0-beta7
- v1.0.0-beta6
- v1.0.0-beta5
- v1.0.0-beta4
- v1.0.0-beta3
- v1.0.0-beta2
- v1.0.0-beta1
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2024-12-18 09:48:47 UTC
README
About RollerworksSearch
RollerworksSearch is a powerful search-system for PHP. Created to make searching in a PHP powered application as simple and fast as possible.
Whether you want to search for users in your SQL database, want to provide a powerful search system for searching products using an ElasticSearch back-end or are looking for a way to abstract filtering for a reporter.
⚠️ RollerworksSearch v2.0 is not stable yet, backward compatible changes should be expected.
If you are looking for a stable version, please wait for a final v2.0 release.
How about complex data structures?
A complex data is structure is no problem, say your customer data is stored in the "customer" table, the "invoices" data is stored in it's own table, and the details of the invoices have there own table.
Instead of writing a very verbose SQL query, your users can use the easy to learn StringQuery syntax:
invoice-price: > $20.00; invoice-row-label: ~*"my cool product"; customer-type: !consumer
.
You just searched in three relational tables using a single condition with a user-friendly syntax. And that is just the start, RollerworksSearch can work with any locale, custom input format, or storage system.
Search conditions can be as simple or complex as you need them to be. Including grouping and nesting for the best possible result.
Features
RollerworksSearch provides you with most of the features you would expect from a search system, including:
- Localized input processing using the StringQuery format;
- User-friendly format validation;
- Integration with API-Platform;
- Integration for Symfony 4.4 and up (Symfony Flex supported).
And support for the most poplar storage systems.
Installation and usage
Please ignore the instructions below if your use a framework integration.
Read the Documentation for complete instructions and information.
Install the RollerworksSearch "core" library using Composer:
$ composer install rollerworks/search
And create the SearchFactory
to get started.
use Rollerworks\Component\Search\Searches; use Rollerworks\Component\Search\Exception\InvalidSearchConditionException; use Rollerworks\Component\Search\Extension\Core\Type\TextType; use Rollerworks\Component\Search\Extension\Core\Type\IntegerType; use Rollerworks\Component\Search\Extension\Core\Type\ChoiceType; use Rollerworks\Component\Search\Input\ErrorPathHumanizer; use Rollerworks\Component\Search\Input\StringQueryInput; use Rollerworks\Component\Search\Input\ProcessorConfig; // The factory is reusable, you create it only once. $searchFactory = Searches::createSearchFactory(); // Create a fieldset to inform the system about your configuration. // Usually you will have a FieldSet for each data structure (users, invoices, etc). $userFieldSet = $searchFactory->createFieldSetBuilder() ->add('firstName', TextType::class) ->add('lastName', TextType::class) ->add('age', IntegerType::class) ->add('type', ChoiceType::class, [ 'choices' => ['Consumer' => 'c', 'Business' => 'b'], ]) ->getFieldSet('users'); // Now lets process a string query. // Tip: the input processor is reusable. $inputProcessor = new StringQueryInput(); try { // The ProcessorConfig allows to limit the amount of values, groups // and maximum nesting level. The defaults should be restrictive enough // for most situations. $processorConfig = new ProcessorConfig($userFieldSet); // The `process` method processes the input and produces // a valid SearchCondition (or throws an exception when something is wrong). $condition = $inputProcessor->process('firstName: sebastiaan, melany;'); } catch (InvalidSearchConditionException $e) { // Each error message can be transformed to a localized version // using the Symfony Translator contract. $translator = ...; // \Symfony\Contracts\Translation\TranslatorInterface // Note: The ErrorPathHumanizer only works for the `StringQueryInput` input processor. $errorPathHumanizer = new ErrorPathHumanizer($translator); foreach ($e->getErrors() as $error) { echo '<span>' $errorPathHumanizer->humanize($error->path) . ' </span><span>' . htmlentities($error->trans($translator), ENT_COMPAT | ENT_IGNORE, 'UTF-8') '</span>' . PHP_EOL; } }
That's it! The $condition
contains the SearchCondition in a normalized
data format which can be used in a condition processor (like ElasticSearch),
or be exported into another format like JSON for easier usage in a URL.
Note: RollerworksSearch is composed of multiple separate packages (to keep the architecture slim), the "core" package provides everything you need to get started.
Searching a (document) storage requires the installation of additional packages.
What about validation?
Each field type ensures the value is transformed to the correct format,
either a date input is automatically transformed to a DateTimeImuttable
object.
A field that expects an integer will fail when the provided input is not an integer.
To enforce more strict constraints like a maximum amount for an integer field you can use the Symfony Validator extension.
Resources
- Read the Documentation
- RollerworksSearch is maintained under the Semantic Versioning guidelines
Who is behind RollerworksSearch?
RollerworksSearch is brought to you by Sebastiaan Stok.
License
RollerworksSearch is released under the MIT license.
The types and extensions are largely inspired on the Symfony Form Component, and contain a big amount of code from the Symfony project.
Support
Use the issue tracker to create a new support question.
Note: Please be patient, it might take some time before your question is answered. Do not ping the maintainers.
Contributing
This is an open source project. If you'd like to contribute, please read the Contributing Guidelines. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section.
Note: RollerworksSearch is developed in a monolith repository, do not open pull request
against repositories marked as [READ-ONLY]
, thank you.