cdwv/sphinx-search-bundle

SphinxSearch 的 Symfony 集成

0.1.1 2015-09-04 10:57 UTC

This package is not auto-updated.

Last update: 2024-09-18 08:53:15 UTC


README

一些 SphinxSearch 与 Symfony 的集成,支持 gigablah/sphinxphpfoolz/sphinxql-query-builderAlt text

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

安装

通过 composer 安装

composer require cdwv/sphinx-search-bundle

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,并且您在本地主机上的 9306 端口上运行 sphinx 守护程序,您不需要提供任何配置。

请注意,$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.defaultSphinx\SphinxClient

$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 开发