ekiwok/sphinxbundle

SphinxSearch 的 Symfony 集成

0.1.0 2015-04-24 11:48 UTC

This package is auto-updated.

Last update: 2024-09-14 10:01:13 UTC


README

gigablah/sphinxphpfoolz/sphinxql-query-builder 提供一些 SphinxSearch 与 Symfony 的集成。 Alt text

版本 0.1.* 在 Codewave 的 shipit day! 期间发布

安装

通过 composer 安装

composer require ekiwok/sphinxbundle

QueryBuilder

您可以注册多个连接。例如配置如下

ekiwok_sphinx:
    connections:
        default:
            host: localhost
            port: 9306
            driver: pdo
        remote:
            host: remote-host
            port: 9306
            driver: mysqli

默认连接将始终创建,除非您提供替代默认配置

    host: localhost
    port: 9306
    driver: pdo

这意味着如果您想使用 pdo 并且在本地主机上运行 Sphinx 守护进程,端口为 9306,您无需提供任何配置。

请注意,$this->get('sphinx')->getConnection()$this->get('sphinx')->getConnection('default') 等价。

sphinx 服务返回的连接实现了 Ekiwok\SphinxBundle\Sphinx\QL\ConnectionInterface,该接口通过 createQueryBuilder() 方法扩展了 Foolz\SphinxQL\Drivers\ConnectionInterface,因此它们可以(并且应该)与 Foolz\SphinxQL 连接互换使用。

使用示例

        $sphinx = $this->get('sphinx');
        $conn = $sphinx->getConnection();
        $recipes = $conn->createQueryBuilder()
                        ->select('id', 'title')
                        ->from('recipes')
                        ->match('title', 'chicken')
                        ->limit(100)
                        ->execute();
        $sphinx = $this->get('sphinx');
        $conn = $sphinx->getConnection();
        $recipes = $conn->query('SELECT id, title FROM recipes WHERE MATCH("(@title chicken)")');

更多内容请访问 https://github.com/FoolCode/SphinxQL-Query-Builder

gigablah/sphinxphp

新用户

如果您是刚开始在项目中使用 Sphinx,您只需声明默认连接即可

    sphinx.default.connection:
        class: Sphinx\SphinxClient
        calls: 
            - [setServer, ['127.0.0.1', 9312] ]

然后装饰它以收集数据

    sphinx.default:
        class: Ekiwok\SphinxBundle\Sphinx\SphinxDataCollector
        arguments: [@sphinx.default.connection, @sphinx_stats]

@sphinx_stats 是提供数据给分析器的服务。您可以通过实现: Ekiwok\SphinxBundle\Sphinx\SphinxDataCollector 来实现自己的提供者

现在像使用 Sphinx\SphinxClient 一样使用 sphinx.default

$sphinxClient = $this->get('sphinx.default');

替换 Sphinx\SphinxClient

Symfony 2.5+

如果您使用的是 Symfony 2.5+,您可能对服务装饰感兴趣: https://symfony.com.cn/doc/current/components/dependency_injection/advanced.html#decorating-services

替换 Sphinx\SphinxClient

如果您已将 SphinxClient 注册为例如 sphinx.default,请使用一个小技巧,将此服务名称更改为 sphinx.default.connection 并将 SphinxDataCollector 注册为 sphinx.default。因为 SphinxDataCollector 扩展了 SphinxClient,它应该对您的项目没有任何副作用

    sphinx.default:
        class: Ekiwok\SphinxBundle\Sphinx\SphinxDataCollector
        arguments: [@sphinx.default.connection, @sphinx_stats]

您始终可以手动实例化 SphinxDataCollector(例如在您没有通过容器管理 SphinxClient 的情况下)

    // $sphinxClient is instance of Sphinx\SphinxClient
    $sphinxStats = $this->get('sphinx_stats');
    $sphinxClient = new \Ekiwok\SphinxBundle\Sphinx\SphinxDataCollector($sphinxClient, $sphinxStats);

此包做什么?

它展示了在分析器和工具栏中的一些花哨的东东。这些东西现在是查询调用和错误。所以它所做的只是跟踪 SphinxClient 查询方法的调用并测量此方法的执行时间(是的,这不是实际的查询时间)。

因为 SphinxClient 使用二进制协议,所以此包不会显示可以复制到 Sphinx CLI 中的真实人类可读的查询。(现在 =)遗憾的是,它只显示了传递给查询方法的参数(查询、索引和注释)。

此包跟踪执行查询期间出现的所有错误。

作者

此包最初由 Piotr Kowalczyk 开发