Skip to content

Commit db2a1d8

Browse files
committed
Merge pull request #132 from murnieza/docs
Documentation for FilterManagerBundle.
2 parents 7c9c01a + 968e400 commit db2a1d8

25 files changed

+1388
-1170
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# ONGR FilterManagerBundle
2+
3+
Filter manager is used for listing documents. It provides ties between commonly used filtering options and UI elements with Elasticsearch repositories.
4+
You can use it from a single controller.
5+
It is important to mention that filtering is everything what has impact on list, it can be:
6+
- Filtering on specific field value object have (color, country etc.)
7+
- Filtering range (price range, distance from point etc.)
8+
- Documents list pagination. Paging changes representation of list, so it is considered to be filter and is treated like one.
9+
- Documents list sorting. Same as paging - sorting is filter in this bundle.
10+
- 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.
11+
12+
[![](https://travis-ci.org/ongr-io/FilterManagerBundle.svg?branch=master)](https://travis-ci.org/ongr-io/FilterManagerBundle)
13+
[![](https://scrutinizer-ci.com/g/ongr-io/FilterManagerBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ongr-io/FilterManagerBundle/?branch=master)
14+
[![](https://scrutinizer-ci.com/g/ongr-io/FilterManagerBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ongr-io/FilterManagerBundle/?branch=master)
15+
[![](https://insight.sensiolabs.com/projects/44c0f05e-a9a8-41ab-9acf-1225cef2887c/mini.png)](https://insight.sensiolabs.com/projects/44c0f05e-a9a8-41ab-9acf-1225cef2887c)
16+
[![](https://poser.pugx.org/ongr/filter-manager-bundle/downloads)](https://packagist.org/packages/ongr/filter-manager-bundle)
17+
[![](https://poser.pugx.org/ongr/filter-manager-bundle/v/stable)](https://packagist.org/packages/ongr/filter-manager-bundle)
18+
[![](https://poser.pugx.org/ongr/filter-manager-bundle/v/unstable)](https://packagist.org/packages/ongr/filter-manager-bundle)
19+
[![](https://poser.pugx.org/ongr/filter-manager-bundle/license)](https://packagist.org/packages/ongr/filter-manager-bundle)
20+
21+
## Instalation
22+
23+
### Step 1: Install FilterManager bundle
24+
25+
FilterManager bundle is installed using [Composer](https://getcomposer.org).
26+
27+
```bash
28+
$ composer require ongr/filter-manager-bundle "~1.0"
29+
```
30+
31+
> Please note that filter manager requires Elasticsearch bundle, guide on how to install and configure it can be found [here](https://github.com/ongr-io/ElasticsearchBundle).
32+
33+
### Step 2: Enable FilterManager bundle
34+
35+
Enable Filter Manager bundle in your AppKernel:
36+
37+
```php
38+
<?php
39+
// app/AppKernel.php
40+
41+
public function registerBundles()
42+
{
43+
$bundles = array(
44+
// ...
45+
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
46+
new ONGR\FilterManagerBundle\ONGRFilterManagerBundle(),
47+
// ...
48+
);
49+
50+
// ...
51+
}
52+
```
53+
54+
### Step 3: Add configuration for manager
55+
56+
Add minimal configuration for Elasticsearch and FilterManager bundles.
57+
58+
```yaml
59+
# app/config/config.yml
60+
61+
ongr_elasticsearch:
62+
connections:
63+
default:
64+
hosts:
65+
- 127.0.0.1:9200
66+
index_name: items
67+
managers:
68+
default:
69+
connection: default
70+
71+
ongr_filter_manager:
72+
managers:
73+
item_list: # <- Filter manager name
74+
filters:
75+
- country
76+
repository: 'es.manager.default.item'
77+
filters:
78+
choice:
79+
country: # <- Filter name
80+
request_field: 'country'
81+
field: country
82+
```
83+
> Note that `Item` document has to be defined. More about that in ElasticsearchBundle [documentation](https://github.com/ongr-io/ElasticsearchBundle/blob/master/Resources/doc/mapping.md).
84+
85+
In this particular example, we defined a single filter manager named `item_list` to filter documents from item repository, and we will be using the filter named `country` to filter on countries defined in document.
86+
87+
### Step 4: Use your new bundle
88+
89+
FilterManagerBundle is ready to use. You can take a look at our [search page example](Resources/doc/examples/search_example.md).
90+
91+
92+
## Documentation
93+
94+
The online documentation of the bundle is in [Github](Resources/doc/index.md).
95+
96+
## License
97+
98+
This bundle is covered by the MIT license. Please see the complete license in the bundle [LICENSE](LICENSE) file.

README.rst

Lines changed: 0 additions & 44 deletions
This file was deleted.

Resources/doc/configuration.rst

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Usage
2+
3+
## Default controller
4+
5+
Once you set up your *managers* you don’t need to create a controller for each one, you can just use default manager controller ONGRFilterManagerBundle:Manager:manager.
6+
7+
Example:
8+
9+
```yaml
10+
# src/AppBundle/Resources/config/routing.yml
11+
12+
ongr_search_page:
13+
pattern: /list
14+
methods: [GET]
15+
defaults:
16+
_controller: ONGRFilterManagerBundle:Manager:manager
17+
managerName: "item_list"
18+
template: "AppBundle:List:results.html.twig"
19+
```
20+
21+
This specific example will render template AppBundle:List:results.html.twig, with [SearchResponse] object from filter manager named item_list.
22+
23+
## Custom controller
24+
25+
You can still use custom controller by getting your needed manager from service container. This way you can add your custom variables if needed.
26+
27+
Example:
28+
29+
```yaml
30+
# src/AppBundle/Resources/config/routing.yml
31+
32+
ongr_search_page:
33+
pattern: /list
34+
methods: [GET]
35+
defaults:
36+
_controller: AppBundle:List:index
37+
```
38+
39+
```php
40+
#src/AppBundle/Controller/ListController.php
41+
42+
/**
43+
* Controller for list pages.
44+
*/
45+
class ListController extends Controller
46+
{
47+
/**
48+
* Renders my list page.
49+
*
50+
* @param Request $request
51+
*
52+
* @return Response
53+
*/
54+
public function indexAction(Request $request)
55+
{
56+
$results = $this->get('ongr_filter_manager.item_list')->execute($request);
57+
58+
return $this->render(
59+
'AppBundle:List:results.html.twig',
60+
[
61+
'filter_manager' => $results,
62+
'my_custom_variable' => $var,
63+
]
64+
);
65+
}
66+
}
67+
```
68+
69+
## Template variables
70+
71+
If you’re using default controller, [SearchResponse] from
72+
[FiltersManager](https://github.com/ongr-io/FilterManagerBundle/blob/master/Search/FiltersManager.php) will be named filter_manager in template, otherwise
73+
it’s whatever you call it in your controller.
74+
75+
You can use [SearchResponse] to get results in your template:
76+
77+
```twig
78+
{% for item in filter_manager.result %}
79+
<b>{{ item.title }}</b>
80+
{% endfor %}
81+
```
82+
83+
You can also use it to get data about your filter:
84+
85+
```twig
86+
Pager url parameters: {{ filter_manager.filters.pager.getUrlParameters() }}
87+
```
88+
89+
A complete list of parameters for each filter can be found can be found
90+
on [main page](../index.md#filters).
91+
92+
[SearchResponse]: https://github.com/ongr-io/FilterManagerBundle/blob/master/Search/SearchResponse.php

0 commit comments

Comments
 (0)