PHPackages                             krzysztof-gzocha/searcher-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. krzysztof-gzocha/searcher-bundle

ActiveLibrary[Search &amp; Filtering](/categories/search)

krzysztof-gzocha/searcher-bundle
================================

Bridge between searcher and Symfony2 framework

3.2.0(9y ago)94183[1 issues](https://github.com/krzysztof-gzocha/searcher-bundle/issues)MITPHPPHP &gt;=5.5.9CI failing

Since Feb 5Pushed 9y ago3 watchersCompare

[ Source](https://github.com/krzysztof-gzocha/searcher-bundle)[ Packagist](https://packagist.org/packages/krzysztof-gzocha/searcher-bundle)[ RSS](/packages/krzysztof-gzocha-searcher-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (15)Used By (0)

[![](https://camo.githubusercontent.com/03659f3fcddeaec49aa2f494c1d4aff0ec9cbd36/687474703a2f2f7777772e636c6b65722e636f6d2f636c6970617274732f612f632f612f382f31313934393936353638313938333637303238396b63616368656772696e642e7376672e7468756d622e706e67)](https://camo.githubusercontent.com/03659f3fcddeaec49aa2f494c1d4aff0ec9cbd36/687474703a2f2f7777772e636c6b65722e636f6d2f636c6970617274732f612f632f612f382f31313934393936353638313938333637303238396b63616368656772696e642e7376672e7468756d622e706e67)

SearcherBundle [![Build Status](https://camo.githubusercontent.com/d9c83d7f5cedbca48b898d21d550c072b7a5eff44024440ce3c8b56e72aca2d3/68747470733a2f2f7472617669732d63692e6f72672f6b727a79737a746f662d677a6f6368612f73656172636865722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/krzysztof-gzocha/searcher-bundle) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/88a0654fdcdfe291e4da58ad64119a843f9e101f1c9b94da19da890b8c15e8ae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b727a79737a746f662d677a6f6368612f73656172636865722d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/krzysztof-gzocha/searcher-bundle/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/ecbd7af804e121fcddb603038dd9c6d558c94c374ec5c4c1c94370dac5013560/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b727a79737a746f662d677a6f6368612f73656172636865722d62756e646c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/krzysztof-gzocha/searcher-bundle/?branch=master) [![SensioLabsInsight](https://camo.githubusercontent.com/32e7476a99370e349f92b9d181390c0a9caf994afba8a9d79dd9511d0c1a4b5c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66393330643430622d303762622d343332302d626664332d3033396639326164323461322f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f930d40b-07bb-4320-bfd3-039f92ad24a2)
==============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#searcherbundle----)

This bundle is providing integration between Symfony and **[Searcher](https://github.com/krzysztof-gzocha/searcher)**

### What is 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: &gt;=5.5, 7 and HHVM.

### Full documentation

[](#full-documentation)

Full documentation can be found at [http://searcher.rtfd.io/](http://searcher.readthedocs.io/en/stable/introduction.html)

### Installation

[](#installation)

You can install this bundle via composer

```
composer require krzysztof-gzocha/searcher-bundle

```

and don't forget to register it in your AppKernel:

```
public function registerBundles()
{
  $bundles = array(
    /** Your bundles **/
    new KGzocha\Bundle\SearcherBundle\KGzochaSearcherBundle(),
  );
  /** rest of the code  **/
}
```

Example usage
-------------

[](#example-usage)

### Config

[](#config)

In config file we will specify minimal configuration for `people` context.
You can full full example of config reference in **[here](https://github.com/krzysztof-gzocha/searcher-bundle/blob/master/src/KGzocha/Bundle/SearcherBundle/configReference.yml)**

```
k_gzocha_searcher:
  contexts:
    people:
      context:
        service: your_searching_context_service_id

      criteria:
        - { class: \AgeRangeCriteria, name: age_range}
        - { service: some_service_id, name: other_criteria }

      builders:
        - { class: \AgeRangeCriteriaBuilder, name: age_range }
        - { service: other_service_id, name: my_criteria_builder }
```

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:

```
$this->get('k_gzocha_searcher.people.searcher');
```

or to access `age_range` criteria:

```
$this->get('k_gzocha_searcher.people.criteria.age_range');
```

or access `my_criteria_builder`:

```
$this->get('k_gzocha_searcher.people.builder.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:

```
your_searching_context_service_id:
  class: KGzocha\Searcher\Context\QueryBuilderSearchingContext
  arguments:
    - @my_search.query_builder  # Or any QueryBuilder service
```

### Code

[](#code)

For this example we will use simple **AgeRangeCriteria** (described in [here](https://github.com/krzysztof-gzocha/searcher)), but of course you can use your own class or service.

```
class AgeRangeCriteria implements CriteriaInterface
{
    private $minimalAge;
    private $maximalAge;

    /**
    * Only required method.
    */
    public function shouldBeApplied()
    {
        return null !== $this->minimalAge && null !== $this->maximalAge;
    }

    // getters, setters, what ever
}
```

We will also use **AgeRangeCriteriaBuilder** (described in [here](https://github.com/krzysztof-gzocha/searcher)), but of course you can use your own class or service.

```
class AgeRangeCriteriaBuilder implements FilterImposerInterface
{
    public function buildCriteria(
        CriteriaInterface $criteria,
        SearchingContextInterface $searchingContext
    ) {
        $searchingContext
            ->getQueryBuilder()
            ->andWhere('e.age >= :minimalAge')
            ->andWhere('e.age add('minimalAge', 'integer', [
                'property_path' => $this->getPath('ageRange', 'minimalAge'),
            ])
            ->add('maximalAge', 'integer', [
                'property_path' => $this->getPath('ageRange', 'maximalAge'),
            ])
            /** and any other fields.. **/
            ->add('', '', [
                'property_path' => $this->getPath(
                    '',
                    ''
                ),
            ]);
    }
}
```

### Controller

[](#controller)

```
public function searchAction(Request $request)
{
    $form = $this->createForm(
        new MySearchForm(),
        $this->get('k_gzocha_searcher.people.criteria_collection')
    );

    $form->handleRequest($request);
    // Now we can check if form is valid

    $searcher = $this->get('k_gzocha_searcher.people.searcher');
    $results = $searcher->search($form->getData());
    // Yay, we have our results!
    // $results is instance of ResultCollection by default. Read for 'wrapper_class'
}
```

### Wrapper class

[](#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
---------------

[](#chain-searching)

Searcher library allows you to perform [chain searching](http://searcher.readthedocs.io/en/stable/chain-search.html) 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:

```
k_gzocha_searcher:
    chains:
        people_log:

          # optional
          chain_searcher:
            class: \KGzocha\Searcher\Chain\ChainSearch
            service: chain_searcher_service

          transformers:
            - name: peopleIdToLogId
              service: transfomer_service
              class: \TransformerClass

          # at least two are required
          cells:
            - name: peopleCell
              searcher: people
              transformer: peopleIdToLogId
              class: \KGzocha\Searcher\Chain\Cell   # optional
              service: cell_service_1               # optional

            - name: logCell
              searcher: logs
              transformer: ~                        # If empty EndTransformer will be used
              class: \KGzocha\Searcher\Chain\Cell   # optional
              service: cell_service_2               # optional
```

With above config you can easily fetch all services like this:

```
$this->get('k_gzocha_searcher.chains.people_log.searcher');         // ChainSearch service

$this->get('k_gzocha_searcher.chains.people_log.cell.peopleCell');  // #1 Cell service
$this->get('k_gzocha_searcher.chains.people_log.cell.logCell');     // #2 Cell service

$this->get('k_gzocha_searcher.chains.people_log.transformer.peopleToLogId'); // Transformer service
```

### Contributing

[](#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

[](#license)

License: MIT
Author: Krzysztof Gzocha [![](https://camo.githubusercontent.com/8e97b75c1e7d875c292b64b2489a7b1f930d25f94a938d618851baa5f5ba1437/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f547769747465722d2534306b677a6f6368612d626c75652e737667)](https://twitter.com/kgzocha)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

14

Last Release

3569d ago

Major Versions

1.1 → 2.02016-04-09

2.1.0 → 3.0.02016-05-19

PHP version history (2 changes)v1.0.0PHP &gt;=5.4

3.0.2PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed214be35ddc1a6bd7dde1ab4ef0ddce47a8308d0883f32532bf453e8f58e4fe?d=identicon)[krzysztof-gzocha](/maintainers/krzysztof-gzocha)

---

Top Contributors

[![krzysztof-gzocha](https://avatars.githubusercontent.com/u/3098559?v=4)](https://github.com/krzysztof-gzocha "krzysztof-gzocha (77 commits)")[![XanderEmu](https://avatars.githubusercontent.com/u/5657795?v=4)](https://github.com/XanderEmu "XanderEmu (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/krzysztof-gzocha-searcher-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/krzysztof-gzocha-searcher-bundle/health.svg)](https://phpackages.com/packages/krzysztof-gzocha-searcher-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/web-profiler-bundle

Provides a development tool that gives detailed information about the execution of any request

2.3k160.5M1.2k](/packages/symfony-web-profiler-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

9410.7k](/packages/ahmed-bhs-doctrine-doctor)[ecotone/symfony-bundle

Ecotone for Symfony — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Symfony Messenger, via PHP attributes.

11249.0k1](/packages/ecotone-symfony-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k13](/packages/2lenet-crudit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
