定制 chris48s/cakephp-searchable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

chris48s/cakephp-searchable

Composer 安装命令:

composer require chris48s/cakephp-searchable

包简介

A CakePHP 3 Behavior for creating MySQL MATCH() AGAINST() queries

README 文档

README

Build Status Coverage Status

CakePHP Searchable Behavior Plugin

A CakePHP 3 Behavior for creating MySQL MATCH() AGAINST() queries.

CakePHP-Searchable adds a custom find('matches') method to your CakePHP models, alleviating the need to pass raw SQL into your queries. It is safe against SQL injection and uses a query syntax which is consistent with the conventions of CakePHP's ORM.

Installation

Install from packagist using composer. Add the following to your composer.json:

"require": {
    "chris48s/cakephp-searchable": "^2.0.0"
}

and run composer install or composer update, as applicable.

Database Support

In order to use FULLTEXT indexes on InnoDB tables, you must be using MySQL >=5.6.4. Earlier versions only allow use of FULLTEXT indexes on MyISAM tables.

Usage

Loading the plugin

Add the code Plugin::load('Chris48s/Searchable'); to your bootstrap.php.

Using the Behavior

Add the behavior in your table class.

<?php
namespace App\Model\Table;

use Cake\ORM\Table;

class MyTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->addBehavior('Chris48s/Searchable.Searchable');
    }
}

Querying data

Having added the behavior to a table class, you now have access to the query method find('matches'), which you can use to construct MATCH() AGAINST() queries. For example:

<?php

use Cake\ORM\TableRegistry;

$myTable = TableRegistry::get('MyTable');

$query = $myTable
    ->find('matches', [
        [
            'match' => 'textcol1',
            'against' => 'foo'
        ],
        [
            'match' => 'textcol2, textcol3',
            'against' => '+foo bar*',
            'mode' => 'IN BOOLEAN MODE'
        ]
    ]);

Available modes are:

  • 'IN NATURAL LANGUAGE MODE'
  • 'IN BOOLEAN MODE'
  • 'WITH QUERY EXPANSION'
  • 'IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION'

When using boolean mode, some additional operators are available.

The method find('matches') returns a CakePHP query object, so you can chain additional methods on to this (e.g: ->where(), ->order(), ->limit(), etc).

Error Handling

If the keys 'match' or 'against' are not set, or if any of the columns contained in the column list are not of type string or text, an exception of class SearchableException will be thrown.

Reporting Issues

If you have any issues with this plugin then please feel free to create a new Issue on the GitHub repository. This plugin is licensed under the MIT Licence.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固