2017 © Pedro Peláez
 

symfony-bundle search-bundle

The SearchBundle adds the ability to use simple elasticsearch search in your application.

image

evheniy/search-bundle

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  • Monday, September 21, 2015
  • by evheniy
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,041 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 3 % Grown

The README.md

SearchBundle

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This bundle provides Search mechanism (elasticsearch) in Symfony2, (*2)

Documentation

You need to set config:, (*3)

search:
    index_name: ~
    index_type: ~
    color_tag_open: <b class="yellow">
    color_tag_close: </b>
    search: 
        fields: [fields]
        parameters: 
            fuzziness: 0.6
            operator: or
            type: best_fields
            tie_breaker: 0.3
            minimum_should_match: 30%
            priorities:
                 field: 10
        filter:
            fields: [fields]
            count: 10
            analyze: true

Installation

Elasticsearch:, (*4)

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.deb
sudo dpkg -i elasticsearch-1.4.4.deb
rm elasticsearch-1.4.4.deb

sudo service elasticsearch start


cd /usr/share/elasticsearch
sudo bin/plugin -install mobz/elasticsearch-head

http://localhost:9200/_plugin/head/

SearchBundle:, (*5)

$ composer require evheniy/search-bundle "1.*"

Or add to composer.json

"evheniy/search-bundle": "1.*"

AppKernel:, (*6)

    public function registerBundles()
        {
            $bundles = array(
                ...
                new Evheniy\SearchBundle\SearchBundle(),
            );
            ...

config.yml:, (*7)

    #SearchBundle
    search:
        index_name: ~
        index_type: ~
        color_tag_open: <b class="yellow">
        color_tag_close: </b>
        search: 
            fields: [fields]
            parameters: 
                fuzziness: 0.6
                operator: or
                type: best_fields
                tie_breaker: 0.3
                minimum_should_match: 30%
                priorities:
                    field: 10
            filter:
                fields: [fields]
                count: 10
                analyze: true

Indexing, (*8)

    $indexer = $this->getContainer()->get('search_index');
    $indexer->deleteIndex();
    $indexer->createIndex();
    foreach ($pages as $page) {
        $indexer->indexDocument(
            DocumentEntity::createFromArray(
                $indexer->getIndexFieldNames(),
                array(
                    'url'     => $page->getUrl(),
                    'title'   => $page->getPageTitle(),
                    'article' => $page->getPageArticle()
                )
            )
        );
    }

indexAction(), (*9)

    $request    = $this->container->get('request');
    $searcher   = $this->container->get('search');
    $searchText = strip_tags(trim($request->get('q')));
    $page       = $request->get('page', 1) < 1 ? 1: $request->get('page', 1);
    $size       = $request->get('size', 10) < 1 ? 10: $request->get('size', 10);

    $filterTitle       = $request->get('filterTitle', array());
    $filterDescription = $request->get('filterDescription', array());

    $results = $searcher->search(
        $searchText,
        $size,
        $page,
        array(
            'filterTitle'       => $filterTitle,
            'filterDescription' => $filterDescription
        )
    );

    return $this->render(
        'AppBundle:Default:index.html.twig',
        array(
            'searchText'  => $searchText,
            'filters'     => $searcher->getFilters(),
            'results' => $results,
            'pagination'  => $searcher->getPaginator()
        )
    );

index.html.twig, (*10)

<div class="searchResults">
        <div class="searchResultsControls">
            {% include "AppBundle:Default:searchFilters.html.twig" %}
        </div>
        <div>
            {% for result in results %}
                <h1><a href="{{ result.url }}">{{ result.title }}</a></h1>
                <article>{{ result.article }}</article>
            {% endfor %}
            <div class="navigation">
                {% include "SearchBundle::pagination.html.twig" %}
            </div>
        </div>
    </div>

searchFilters.html.twig, (*11)

{% for key,filter in filters %}
    <div>
        <div>
            <h3 class="label">
                {{- ('index.filters.'~key)|trans({}, 'AppBundle') -}}
            </h3>
            <div class="options">
                <ul>
                    {% for field in filter %}
                        <li{% if field.isActive %} class="selected"{% endif %}>
                            <a class="item" href="{{ path('homepage', field.url) }}">
                                <span class="name">{{ field.name|upper }}</span>
                                <span class="restaurantCount">{{ field.count }}</span>
                            </a>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>
{% endfor %}

License

This bundle is under the MIT license. See the complete license in the bundle:, (*12)

Resources/meta/LICENSE

[MakeDev.org][1], (*13)

The Versions

21/09 2015

dev-master

9999999-dev

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

18/09 2015

1.0.11

1.0.11.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

18/09 2015

1.0.10

1.0.10.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

30/04 2015

1.0.8

1.0.8.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

29/04 2015

1.0.7

1.0.7.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

14/04 2015

1.0.6

1.0.6.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

14/04 2015

1.0.5

1.0.5.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

14/04 2015

1.0.4

1.0.4.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

10/04 2015

1.0.3

1.0.3.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

10/04 2015

1.0.2

1.0.2.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

06/04 2015

1.0

1.0.0.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

05/04 2015

0.2

0.2.0.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets

05/04 2015

0.1

0.1.0.0

The SearchBundle adds the ability to use simple elasticsearch search in your application.

  Sources   Download

MIT

The Requires

 

search elasticsearch symfony2 simple facets