ONGR FilterManagerBundle

ONGR 过滤器管理器捆绑包用于列出文档。它将常用过滤选项和用户界面元素与 Elasticsearch 资源库联系起来。「Filter manager is used for listing documents. It provides ties between commonly used filtering options and UI elements with Elasticsearch repositories.」

Github星跟踪图

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:

  • Filtering on specific field value object have (color, country etc.)
  • Filtering range (price range, distance from point etc.)
  • Documents list pagination. Paging changes representation of list, so it is considered to be filter and is treated like one.
  • Documents list sorting. Same as paging - sorting is filter in this bundle.
  • Any custom factor which has influence (not always directly visible) on result list. It can exclude, boost, modify some results, collect some metrics or any other action you can imagine.

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 "~3.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:

// config/bundles.php

<?php

return [
    ...

    ONGR\ElasticsearchBundle\ONGRElasticsearchBundle::class => ['all' => true],
    ONGR\FilterManagerBundle\ONGRFilterManagerBundle::class => ['all' => true],
    JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],

    ...
];

Step 3: Add configuration for manager

Add minimal configuration for Elasticsearch and FilterManager bundles.

# app/config/config.yml

ongr_elasticsearch:
  indexes:
    App\Document\Product:
      hosts: 
         - 127.0.0.1:9200 

ongr_filter_manager:
    managers:
        search_list: # <- Filter manager name
            filters:
                - country
            repository: App\Document\Product # <- Product document rindex service (used to be a repository prior to v3.0)
    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
 
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.

主要指标

概览
名称与所有者ongr-io/FilterManagerBundle
主编程语言PHP
编程语言PHP (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2014-10-29 16:04:43
推送于2022-05-30 08:51:07
最后一次提交2022-05-30 11:50:01
发布数30
最新版本名称v3.1.0 (发布于 )
第一版名称v0.1.0 (发布于 2014-10-30 13:56:39)
用户参与
星数26
关注者数19
派生数43
提交数537
已启用问题?
问题数87
打开的问题数16
拉请求数157
打开的拉请求数2
关闭的拉请求数15
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?