承接 voycey/cakephp-sphinxsearch 相关项目开发

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

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

voycey/cakephp-sphinxsearch

Composer 安装命令:

composer require voycey/cakephp-sphinxsearch

包简介

Sphinxsearch plugin for CakePHP 3.x

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

For earlier versions of CakePHP (2.x)

Please use the 2.x branch and follow the readme instructions under that for usage instructions

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require voycey/cakephp-sphinxsearch

##Basic Documentation

I designed this as a replacement for the binary API access for Sphinxsearch that I was using on 2.x (https://github.com/voycey/sphinxsearch-cakephp2)

It currently has one function and that is to query the provided index and return the matching records in a CakePHP friendly format (In this case as Query objects and Entities).

##How to use

  • Install the package with composer as above
  • Add Plugin::load('Sphinx'); to your bootstrap.php
  • Attach the behaviour to a table you wish to search on (There must be an index that is generated from this model - the behaviour works by pulling the ID's from Sphinx and then fetching them from the DB (See TODO's for improving this)
  • Behavior config options:
    • 'connection' => ['host' => 'hostname', 'port' => 'port'] (default hostname is 'localhost' and default port is 9306)
    • 'defaultIndex' => 'index_name'
<?php 
class PostsTable extends Table
{

    /**
     * Initialize method
     *
     * @param  array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('posts');
        $this->displayField('title');
        $this->primaryKey('id');

        $this->addBehavior('Timestamp');
        $this->addBehavior('Sphinx.Sphinx');
    }
}
  • Perform a search through the behaviour directly (This will return a query object), it takes an array of the following parameters:

    • index - this is the index you want to search against
    • term - this is the term you want to search for
    • match_fields - these are the fields you want to search against (default is search whole index)
    • pagination - this is a standard Cake 3 pagination array - allows you to define how your data comes back, what fields it contains and what Models are contained.
    • limit - this is the number of results to limit to, currently defaults to 1000

Here is an example unit test that works for me.

public function testBehaviour()
{
    $paginate = [
        'order' => [
            'Posts.id asc'
        ],
        'fields' => [
            'id', 'title', 'user_id'
        ],
        'contain' => [
            'Comments' => [
                'fields' => ['id', 'post_id']
            ],
            'Categories' => [
                'fields' => ['id', 'CategoriesPosts.post_id']
            ],
            'Types' => [
                'fields' => ['id', 'name']
            ]
        ]
    ];

    $query = $this->Posts->search([
                                    'index' => 'idx_toolkit', 
                                    'term' => 'Ten', 
                                    'match_fields' => 'title', 
                                    'paginate' => $paginate,
                                    'limit' => 50
                                ]);
    
    $row = $query->first();

    $this->assertInstanceOf('Cake\ORM\Query', $query);
    $this->assertInstanceOf('Cake\ORM\Entity', $row);

}

###TODO

  • Give option for all data to be pulled from Sphinxsearch directly rather than then querying DB
  • Hook into afterSave and have the Sphinx index updated (this isn't a priority for me as my indexes don't need to be live but please submit a pull request if you want to add this)
  • Work out how to test this easily on Travis (again - help appreciated)

voycey/cakephp-sphinxsearch 适用场景与选型建议

voycey/cakephp-sphinxsearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 voycey/cakephp-sphinxsearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 voycey/cakephp-sphinxsearch 我们能提供哪些服务?
定制开发 / 二次开发

基于 voycey/cakephp-sphinxsearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-14