scorpio/sphinx-search-bundle

此包已废弃,不再维护。作者建议使用 foolz/sphinxql-query-builder 包。

为 scorpio/sphinx-search 添加包装器和配置的 Symfony 包。

安装: 137

依赖者: 0

建议者: 0

安全: 0

星星: 1

观察者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

0.2.0 2017-09-02 19:40 UTC

This package is auto-updated.

Last update: 2022-02-01 12:51:40 UTC


README

此项目已废弃。请切换到:foolz/sphinxql-query-builder https://github.com/FoolCode/SphinxQL-Query-Builder

Scorpio SphinxSearchBundle

SphinxSearchBundle 为 Scorpio SphinxSearch 添加配置和服务支持,使其在 Symfony 项目中使用更加方便。

需求

  • Symfony 3+
  • Scorpio SphinxSearch
  • 对于 composer 安装,需要 PHP Sphinx 扩展

安装

  1. 推荐方法是通过 composer 安装

    composer require scorpio/sphinx-search-bundle

  2. 在您的 AppKernel 中启用此包

    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Scorpio\SphinxSearchBundle\ScorpioSphinxSearchBundle(),
            // ...
        );
    }
  3. 在您的 config.yml 中设置配置参数

  4. 映射一些索引(见后文)

基本用法

此包公开以下配置

scorpio_sphinx_search:
    host: localhost
    port: 9312
    max_query_time: 3000 # max query execution time

可选地,可以指定一个特定的 SphinxClient 类来处理连接。如果 PHP 扩展不可用且不能使用 SphinxQL 库,可以使用此功能。

scorpio_sphinx_search:
    client_class: SomeClass\That\Implements\SphinxClientAPI

以下服务会自动注册

  • scorpio_sphinx_search.server.settings (私有)
  • scorpio_sphinx_search.search_manager (主搜索管理实例)

可以将索引配置为服务

services:
    my_custom_sphinx_index:
        class: Scorpio\SphinxSearch\SearchIndex
        arguments:
           - 'my_custom_sphinx_index'
           - [ 'available', 'fields', 'as_an_array' ]
           - [ 'attribute1', 'attribute2' ]

注意:索引名称和字段是必需的,必须与 Sphinx 配置中公开的内容相匹配。

此外,还可以指定结果集和结果记录类

services:
    my_custom_sphinx_index:
        class: Scorpio\SphinxSearch\SearchIndex
        arguments:
           - 'my_custom_sphinx_index'
           - [ 'available', 'fields', 'as_an_array' ]
           - [ 'attribute1', 'attribute2' ]
           - 'MyResultSet'
           - 'MyCustomResult'

最后,对于真正懒惰的用户,索引定义可以标记为具有自定义属性 "query" 设置为 true

services:
    my_custom_sphinx_index:
        tags:
            - { name: scorpio_sphinx_search.index, query: true }

然后容器中会自动注册一个自定义查询服务。前缀可以在您的 parameters.yml 中自定义,默认值(如果未设置)是 "query",因此之前的标记将创建服务: "query.my_custom_sphinx_index"。

注意:必须将 "query" 属性设置为 true,否则索引将被忽略。这允许服务被标记和定位以进行调试,但不需要时不会自动创建查询服务。

然后您可以在控制器中访问查询实例

class MyController extends Controller
{

    function indexAction(Request $request)
    {
        // bind a search term somehow, apply filters etc. maybe check for keywords...
        $query = $this
            ->get('query.my_custom_sphinx_index')
            ->setQuery($request->query->get('keywords'));

        $results = $this->get('scorpio_sphinx_search.search_manager')->query($query);

        // do something with the results.
    }
}

许可证

此包在 BSD 许可证下授权。请参阅包 LICENSE 文件中的完整许可证。

问题或功能请求

应该在 Github 存储库页面 上提出问题或功能请求。