gnugat/search-engine-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

A gnugat/search-engine integration in symfony

Installs: 76

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:symfony-bundle

v0.3.1 2015-12-01 10:28 UTC

This package is auto-updated.

Last update: 2022-02-01 12:50:33 UTC


README

A gnugat/search-engine integration in Symfony.

Caution: this component does not provide actual SearchEngine features, if you're looking for one you should rather have a look at ElasticSearch, Solr, etc. See gnugat/search-engine's' website for more information.

This bundle provides the following services:

  • gnugat_search_engine.criteria_factory: creates Criteria from Request query parameters
  • gnugat_search_engine.identifier_engine: an instance of IdentifierEngine
  • gnugat_search_engine.search_engine: an instance of SearchEngine
  • gnugat_search_engine.type_sanitizer: an instance of TypeSanitizer

In order for it to work, you need to:

  1. create an implementations of Fetcher (or install an existing one, like PommSearchEngine)
  2. define it as a service with the name gnugat_search_engine.fetcher

Also, to be able to find anything SearchEngine and IdentifierEngine both need you to add information about available resources. This can be done by implementating SelectBuilder and define it as a service, for example:

services:
    app.blog_select_builder:
        class: AppBundle\SearchEngine\BlogSelectBuilder
        tags:
            -
                name: gnugat_search_engine.select_builder
                resource_name: blog
                resource_definition: |
                    {
                        "fields": {
                            "id": "integer",
                            "title": "string",
                            "author_id": "integer"
                        },
                        "relations": ["author"]
                    }

We can finally use it, for example in a controller:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class BlogController extends Controller
{
    /**
     * Full URL example: /v1/blogs?title=IG&sort=author_id,-title&page=2&per_page=1
     *
     * @Route("/v1/blogs")
     * @Method({"GET"})
     */
    public function searchAction(Request $request)
    {
        $criteriaFactory = $this->container->get('gnugat_search_engine.criteria_factory');
        $searchEngine = $this->container->get('gnugat_search_engine.search_engine');

        $criteria = $criteriaFactory->fromQueryParameters('blog', $request->query->all());
        $results = $searchEngine->match($criteria);

        return new Response(json_encode($results), 200, array('Content-Type' => 'application/json'));
    }
}

Tip: instead of using these services directly in the controller, we can inject them in other services.

Installation

To install gnugat/search-engine-bundle, run the following command:

composer require gnugat/search-engine-bundle:^0.3

Then register Gnugat\SearchEngineBundle\GnugatSearchEngineBundle in AppKernel.php

Further documentation

You can see the current and past versions using one of the following:

You can find more documentation at the following links: