Download the PHP package krzysztof-gzocha/searcher-bundle without Composer
On this page you can find all versions of the php package krzysztof-gzocha/searcher-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download krzysztof-gzocha/searcher-bundle
More information about krzysztof-gzocha/searcher-bundle
Files in krzysztof-gzocha/searcher-bundle
Package searcher-bundle
Short Description Bridge between searcher and Symfony2 framework
License MIT
Informations about the package searcher-bundle
SearcherBundle

This bundle is providing integration between Symfony and Searcher
What is Searcher?
Searcher is a library completely decoupled from any framework created in order to simplify construction of complex searching queries basing on passed criteria. It's basic idea is to split each searching filter to separate class. Regardless of what do you want to search: entities in MySQL, MongoDB or just files. Supported PHP versions: >=5.5, 7 and HHVM.
Full documentation
Full documentation can be found at http://searcher.rtfd.io/
Installation
You can install this bundle via composer
and don't forget to register it in your AppKernel:
Example usage
Config
In config file we will specify minimal configuration for people
context.
You can full full example of config reference in here
As you can see you can specify everything as a simple class or as your own service.
This configuration will create our people
context and create all required services (builder collection, criteria collection, searcher and context), so you can access them and make use of them. For example to access Searcher instance from controller you can simply:
or to access age_range
criteria:
or access my_criteria_builder
:
I guess it's pretty easy to understand this naming convention.
In this example you need to define only 1 service on your own - SearchingContext service with id specified in the config (your_searching_context_service_id
). You can do it like this:
Code
For this example we will use simple AgeRangeCriteria (described in here), but of course you can use your own class or service.
We will also use AgeRangeCriteriaBuilder (described in here), but of course you can use your own class or service.
Form (optional)
Now we can create example form. Form will allow Symfony to take care of population and validation our criteria from request. This step is optional and you don't have to populate criteria from request. You can do this however you want to.
Controller
Wrapper class
By default SearcherBundle will wrap Searcher into WrappedResultsSearcher
,
which will return ResultCollection
which has method getResults()
that will return collection of your results.
Of course ResultCollection
itself is traversable, so you can use it inside foreach
loop.
This feature is useful in rare situations where you are not sure if your QueryBuilder
will return array or traversable object. Returning null
and trying to iterate over it will lead to an error. ResultCollection will prevent this kind of situation. If you want to change wrapper class then you need to specify wrapper_class
in searcher config.
Of course sometimes you want your Searcher to just return an integer or whatever, then you do not want to wrap your Searcher. In order to do that just specify wrapper_class
as null
Chain searching
Searcher library allows you to perform chain searching and
you can use with this bundle as well. All what you need to do is to properly configure it in config file and fetch
ChainSearch
service.
Example chain searching config:
With above config you can easily fetch all services like this:
Contributing
All ideas and pull request are welcomed and appreciated. Please, feel free to share your thought via issues.
Command to run tests: composer test
.
License
All versions of searcher-bundle with dependencies
symfony/framework-bundle Version >=2.3
krzysztof-gzocha/searcher Version ~4.0.0