ONGR FilterManagerBundle

Filter manager is used for listing documents. It provides ties between commonly used filtering options and UI elements with Elasticsearch repositories. It is important to mention that filtering is everything what has impact on list, it can be:

If you need any help, stack overflow is the preffered and recommended way to ask ONGR support questions.

Build Status Coverage Status Latest Stable Version Scrutinizer Code Quality

Documentation

For online documentation of the bundle click here. All docs pages are located in Resources/doc/.

Installation

Step 1: Install FilterManager bundle

FilterManager bundle is installed using Composer.

# You can require any version you need, check the latest stable to make sure you are using the newest version.
$ composer require ongr/filter-manager-bundle "~2.0"

Please note that filter manager requires Elasticsearch bundle, guide on how to install and configure it can be found here.

Step 2: Enable FilterManager bundle

Enable Filter Manager bundle in your AppKernel:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
        new ONGR\FilterManagerBundle\ONGRFilterManagerBundle(),
        new \JMS\SerializerBundle\JMSSerializerBundle(),
    ];
    
    // ...
}

Step 3: Add configuration for manager

Add minimal configuration for Elasticsearch and FilterManager bundles.

# app/config/config.yml

ongr_elasticsearch:
    managers:
        default:
            index: 
                hosts:
                    - 127.0.0.1:9200
                index_name: products

ongr_filter_manager:
    managers:
        search_list: # <- Filter manager name
            filters:
                - country
            repository: es.manager.default.product # <- Product document repository service to execute queries on
    filters:
        country: # <- Filter name
            type: choice
            request_field: country
            document_field: country

Note that Product document has to be defined. More about that in ElasticsearchBundle documentation.

In this particular example, we defined a single filter manager named search_list to filter documents from product repository, and we will be using the filter named country to filter on countries defined in document.

Step 4: Use your new bundle

FilterManagerBundle is ready to use. When you define filter manager the bundle generates a service according manager name. In this particular case it will be ongr_filter_manager.manager.search_list.

To get a list grab the service and call handleRequest(). Here's a short example in the controller:

`php <?php

use ONGR\FilterManagerBundle\DependencyInjection\ONGRFilterManagerExtension; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response;

class ProductController extends Controller {

  /**
   * @param Request $request Request.
   *
   * @return Response
   */
  public function listAction(Request $request)
  {
      $searchList = $this->get(ONGRFilterManagerExtension::getFilterManagerId('search_list'))
                        ->handleRequest($request);
      $this->render(
          'AppBundle:Product:list.html.twig',
          [
            'filters' => $searchList->getFilters(),  
            'products' => $searchList->getResult(),  
          ]
      );                  
  }

} `

> More information how to use filters and render the results are in basics topic here.

Troubleshooting

If you face any issue or difficulty by implementing bundle, do not be afraid to create an issue with bug or question. Also ONGR organization has a tag in Stackoverflow so you can ask about all ONGR bundles also there.

License

This bundle is covered by the MIT license. Please see the complete license in the bundle LICENSE file.