2017 © Pedro Peláez
 

symfony-bundle search-bundle

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

image

liip/search-bundle

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  • Friday, June 30, 2017
  • by dbu
  • Repository
  • 39 Watchers
  • 38 Stars
  • 73,629 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 12 Forks
  • 5 Open issues
  • 12 Versions
  • 1 % Grown

The README.md

LiipSearchBundle

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

This bundle provides a uniform interface for full text search with various search engines and a controller with twig templates to render search forms and results., (*2)

Note: You are looking at Version 2 of this bundle, which saw large changes compared to Version 1., (*3)

Introduction

This search bundle simplifies adding search to your site., (*4)

Provided for you are:, (*5)

  • A controller to render a search box and the search page with twig templates
  • A service to query google site search
  • A service which provides paging for the search results

Built-in Search Engines Support

For now, Google site search is supported out of the box. There is one implementation using the Google REST API and one implementation using the Custom Search Element feature that loads the search with only javascript in the frontend., (*6)

Contributions for other services are welcome., (*7)

Installation

Install the bundle with composer require liip/search-bundle., (*8)

Include the bundle in app/Kernel.php., (*9)

Add your preferred search engine in app/config/config.yml:, (*10)

liip_search:
    clients:
        google_rest:
            api_key: '%google.api_key%'
            search_key: '%google.search_key%'

Or if you use the javascript Google custom search engine:, (*11)

liip_search:
    clients:
        google_cse:
            cse_id: '%google.search_key%'

Usage

You can display a search box anywhere on the page with the liip_search_box twig function:, (*12)

``` jinja {{ liip_search_box(query, 'query-field-id', 'css-class') }}, (*13)


You can customize the search box with these parameters: * query - default query to display * fieldId - HTML id to use for the search input field. Use different ids when having more than one search box on your page, e.g. in the header and in content. * cssClass - A css class to apply to the whole search box `<form>`. Create a route for the search action. The easiest is to just use the provided routing.xml from your main project routing.xml:
liip_search:
    resource: "@LiipSearchBundle/Resources/config/routing.xml"

```, (*14)

It defaults to the URL /search. If you want a different route, use the prefix option when including the route or configure your own route using %liip_search.controller.search_action% as default value for _controller., (*15)

Customizing Templating

The search result templates provided by this bundle extend the LiipSearchBundle::layout.html.twig template. To integrate with the rest of your site, you have two options:, (*16)

  • Create app/Resources/LiipSearchBundle/views/layout.html.twig and make it extend your base layout, putting a liip_search_content block where you want the search results.
  • Create app/Resources/LiipSearchBundle/views/Search/search.html.twig and build your own templating structure - you should be able to use the search_results.twig.html template to get the liip_search_content block.

Of course you can also override any of the templates to customize what they should do. See http://symfony.com/doc/master/book/templating.html#overriding-bundle-templates, (*17)

Configuration Reference

This is the full reference of what you can configure under the liip_search key:, (*18)

search_factory, (*19)

string, default value: null, (*20)

Specify a custom service that implements the Liip\SearchBundle\SearchFactoryInterface. This service will be used by the controller to create Pagerfanta instances to handle the search., (*21)

If you configure one of the search engine services, you do not need to set this field., (*22)

search_route, (*23)

string, default value: liip_search, (*24)

The name of the route that will handle submitted search requests., (*25)

restrict_language, (*26)

boolean, default value: false, (*27)

Change this to true if you want to ask the search service to restrict the results to the language of the request., (*28)

Google Search REST API Integration

Configuring any of these options enables the google search engine service. They are located under clients.google_rest., (*29)

api_key, (*30)

string, required, (*31)

Your Google API key, (*32)

search_key, (*33)

string|array, required, (*34)

The key identifying your Google Search Engine. May be a list of keys indexed by locale to use different engines per locale. If you control locales through separate search engines, you do not need to set restrict_language to true unless you want your custom search engines to receive a language restriction additionally., (*35)

api_url, (*36)

string, default value: https://www.googleapis.com/customsearch/v1, (*37)

The Google Search API URL for REST calls, (*38)

restrict_to_site, (*39)

string, default value: null, (*40)

If left empty, all sites configured for the google search engines are searched. Set to a a domain to limit to that domain., (*41)

Google Custom Search Engine Integration

Configuring this section activates a different controller that renders the Javascript fragment to enable the CSE search. This configuration is located under clients.google_cse., (*42)

cse_id, (*43)

string|array, required, (*44)

The key identifying your Google Custom Search Engine. May be a list of keys indexed by locale to use different engines per locale. CSE does not support the restrict_language, so different search engines per language are your only option to restrict the language of search results., (*45)

Troubleshooting

Google Custom Search Engine

If you get SearchException saying "Empty response received from Google Search Engine API", try copying the URL that is output into a browser. You should get JSON response, but likely it will haves an error status., (*46)

If you get a status 500 with an empty message, chances are that you need to renew the search engine in the Google admin panel., (*47)

Adding your own Search Service

Implement the Liip\SearchBundle\SearchInterface and configure it as a service. Then set liip_search.search_client to that service name., (*48)

TODO

  • Use guzzle to talk to google REST API
  • Add support for refinements (more like this) with info in search result array that can be passed to SearchInterface::refineSearch
  • Expose more of the google search parameters

The Versions

30/06 2017

dev-bing_web_search_client

dev-bing_web_search_client

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

09/05 2016

dev-master

9999999-dev

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

09/05 2016

2.0.0

2.0.0.0

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

09/05 2016

2.0.x-dev

2.0.9999999.9999999-dev

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

26/10 2015

2.0.0-beta2

2.0.0.0-beta2

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

29/08 2015

1.0.x-dev

1.0.9999999.9999999-dev

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

09/06 2015

1.0.2

1.0.2.0

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

12/02 2015

2.0.0-beta1

2.0.0.0-beta1

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

09/02 2015

2.0.0-alpha2

2.0.0.0-alpha2

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

05/02 2015

2.0.0-alpha1

2.0.0.0-alpha1

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

19/01 2015

1.0.1

1.0.1.0

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2

11/06 2013

1.0.0

1.0.0.0

This bundles provides some basic infrastructure for creating a search UI in Symfony2 applications along with integration with Google's search API

  Sources   Download

MIT

The Requires

 

symfony2