manugarciaes / easy-search-bundle
Easy way to integration ElasticaBundle in your project with filters, aggregations, ...
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- friendsofsymfony/elastica-bundle: ^3.1
- symfony/symfony: ~2.7.7
This package is not auto-updated.
Last update: 2025-03-01 22:04:39 UTC
README
-
You need Fos Elastica Bundle installed and configurated
-
Add SearchBundle to your appKernel
$bundles = array( [..] new manugarciaes\SearchBundle\SearchBundle(), );
-
Change your Fos Elastica Bundle configuration, using as repository the next one
persistence: [..] repository: manugarciaes\SearchBundle\Repository\SearchRepository
-
Create a new service using the Easy Search Service like next example:
If you want Add Filters
-
create a new service with Easy Search Filter Object
## FILTER EXAMPLE elastic.search.filter.enabled: class: SearchBundle\Filter\ObjectFilter calls: - [setField, ['enabled']] - [setValue, [true]]
If you want a dynamic value you can use for example a service or something like this:
- [setValue, ["@=service('request_stack').getMasterRequest.get('enabled')"]]
With this your filter change the value using the request
-
Add this filter to your Search Service
EXAMPLE
article.search: class: SearchBundle\Services\SearchService arguments: - "@fos_elastica.manager.orm" - %elastica_entity% - ['%search_string%'] calls: - [addFilter, ['@elastic.search.filter.enabled']]
If you want add Aggregations
-
Create a new service with Easy Search Aggregation Object
## example elastic.search.aggregation.categories: class: Elastica\Aggregation\Terms arguments: - %name% calls: - [setField, ['%category_field%']] - [setSize, [%category_size%]]
-
Add this aggregation to your Easy Search Service
EXAMPLE
article.search:
class: SearchBundle\Services\SearchService
arguments:
- "@fos_elastica.manager.orm"
- %elastica_entity%
- ['%search_string%']
calls:
- [addAggregation, [@elastic.search.aggregation.categories]]
Now you can make a search using this service, example:
$searchService = $this->get('article.search');
$results = $searchService->search('hello');