2017 © Pedro Peláez
 

symfony-bundle search-bundle

Site search bundle for Symfony2

image

chub/search-bundle

Site search bundle for Symfony2

  • Monday, January 11, 2016
  • by Chub
  • Repository
  • 3 Watchers
  • 6 Stars
  • 110 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

SearchBundle

Search Symfony2 bundle. Provides easy global search service for your site., (*1)

Build Status, (*2)

knp, (*3)

Installation

Download bundle

First of all, download bundle using one of common ways:, (*4)

Using deps file

Add the following lines to your deps file and run php bin/vendors install, (*5)

[SearchBundle]
    git=https://github.com/ChubV/SearchBundle.git
    target=bundles/ChubProduction/SearchBundle

Using composer

Register the namespaces

Add the following namespace entry to the registerNamespaces call in your autoloader:, (*6)

``` php <?php // app/autoload.php $loader->registerNamespaces(array( // ... 'ChubProduction\SearchBundle' => DIR.'/../vendor/bundles', // ... ));, (*7)


This is unnecessary step if you use Composer's automaticaly generated autoload file ### Register the bundle To start using the bundle, register it in your Kernel: ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new ChubProduction\SearchBundle\SearchBundle(), ); // ... }

Create your search provider, that must implement SearchProviderInterface, (*8)

``` php <?php // NewsSearchProvider.php, (*9)

class NewsSearchProvider implements SearchProviderInterface { private $m;, (*10)

/**
 * @param string $str
 *
 * @return \Doctrine\Common\Collections\ArrayCollection
 */
public function search($str)
{
    // Perform search and return ArrayCollection of objects that implements SearchResultInterface
    // There is also default SearchResult class for this ChubProduction\SearchBundle\Service\SearchResult
}

/**
 * Return provider name
 *
 * @return string
 */
public function getName()
{
    return 'news';
}

/**
 * Return provider title
 *
 * @return string
 */
public function getTitle()
{
    return 'News, events, etc ';
}

Register search provider among other ones ``` yaml # services.yml news.search.provider: class: ChubProduction\NewsBundle\Search\NewsSearchProvider tags: - { name: search.provider } content.search.provider: class: ... tags: - { name: search.provider } ....

Use the search getting an ArrayCollection of ResultSets with the results from your search providers, (*11)

``` php <?php ... /** * @return array|\Symfony\Component\HttpFoundation\RedirectResponse * @Route("/search/{_locale}", name="search") * @Template() */ public function searchAction($_locale) { $r = $this->getRequest(); if ($r->query->has('q')) { $res = $this->get('search')->search($r->query->get('q')); // Here is our service, (*12)

        return compact('res');
    }

    return $this->redirect($this->generateUrl('main_page', compact('_locale')));
}

```, (*13)

The Versions

11/01 2016

dev-master

9999999-dev https://github.com/ChubV/SearchBundle

Site search bundle for Symfony2

  Sources   Download

The Requires

 

search bundle

25/01 2013

2.1.x-dev

2.1.9999999.9999999-dev https://github.com/ChubV/SearchBundle

Site search bundle for Symfony2

  Sources   Download

The Requires

 

search bundle