承接 gnugat/search-engine-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gnugat/search-engine-bundle

最新稳定版本:v0.3.1

Composer 安装命令:

composer require gnugat/search-engine-bundle

包简介

A gnugat/search-engine integration in symfony

README 文档

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:

统计信息

  • 总下载量: 78
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-23