2017 © Pedro Peláez
 

symfony-bundle easy-search-bundle

Easy way to integration ElasticaBundle in your project with filters, aggregations, ...

image

manugarciaes/easy-search-bundle

Easy way to integration ElasticaBundle in your project with filters, aggregations, ...

  • Friday, June 3, 2016
  • by manugarciaes
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

SearchBundle for ElasticaBundle

1) You need Fos Elastica Bundle installed and configurated 2) Add SearchBundle to your appKernel, (*1)

$bundles = array(
[..]
    new manugarciaes\SearchBundle\SearchBundle(),
);

3) Change your Fos Elastica Bundle configuration, using as repository the next one, (*2)

 persistence:
    [..]
    repository: manugarciaes\SearchBundle\Repository\SearchRepository

4) Create a new service using the Easy Search Service like next example: - elastica_entity is the fos elastica entity in your configuration - search_string is the fields of your entity where you want to search, (*3)

  ##  EXAMPLE  
  article.search:
    class: SearchBundle\Services\SearchService
    arguments:
      - "@fos_elastica.manager.orm"
      - %elastica_entity%
      - ['%search_string%']

If you want Add Filters, (*4)

1) create a new service with Easy Search Filter Object, (*5)

    ## 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:, (*6)

   - [setValue, ["@=service('request_stack').getMasterRequest.get('enabled')"]]

With this your filter change the value using the request, (*7)

2) Add this filter to your Search Service, (*8)

  ##  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, (*9)

1) Create a new service with Easy Search Aggregation Object, (*10)

        ## example
        elastic.search.aggregation.categories:
          class: Elastica\Aggregation\Terms
          arguments:
            - %name%
          calls:
            - [setField, ['%category_field%']]
            - [setSize, [%category_size%]]

2) Add this aggregation to your Easy Search Service, (*11)

## EXAMPLE article.search: class: SearchBundle\Services\SearchService arguments: - "@fos_elastica.manager.orm" - %elastica_entity% - ['%search_string%'] calls: - [addAggregation, [@elastic.search.aggregation.categories]], (*12)

Now you can make a search using this service, example:, (*13)

       $searchService = $this->get('article.search');
       $results = $searchService->search('hello');

The Versions

03/06 2016

dev-master

9999999-dev https://github.com/manugarciaes/EasySearchBundle

Easy way to integration ElasticaBundle in your project with filters, aggregations, ...

  Sources   Download

MIT

The Requires

 

by Manuel Garcia

search elasticsearch fos elastica elasticabundle elasticbundle

03/06 2016

0.1

0.1.0.0 https://github.com/manugarciaes/SearchBundle

Easy way to integration ElasticaBundle in your project with filters, aggregations, ...

  Sources   Download

MIT

The Requires

 

by Manuel Garcia

search elasticsearch fos elastica elasticabundle elasticbundle