2017 © Pedro Peláez
 

cakephp-plugin cakephp-searchable

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

image

chris48s/cakephp-searchable

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

  • Thursday, May 10, 2018
  • by chris48s
  • Repository
  • 2 Watchers
  • 2 Stars
  • 173 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

Build Status Coverage Status, (*1)

CakePHP Searchable Behavior Plugin

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

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., (*3)

Installation

Install from packagist using composer. Add the following to your composer.json:, (*4)

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

and run composer install or composer update, as applicable., (*5)

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., (*6)

Usage

Loading the plugin

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

Using the Behavior

Add the behavior in your table class., (*8)

<?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:, (*9)

<?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', (*10)

When using boolean mode, some additional operators are available., (*11)

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

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., (*13)

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., (*14)

The Versions

10/05 2018

dev-master

9999999-dev https://github.com/chris48s/cakephp-searchable

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar chris48s

cakephp search mysql fulltext searchable

10/05 2018

2.0.0

2.0.0.0 https://github.com/chris48s/cakephp-searchable

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar chris48s

cakephp search mysql fulltext searchable

11/09 2017

1.1.0

1.1.0.0 https://github.com/chris48s/cakephp-searchable

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar chris48s

cakephp search mysql fulltext searchable

09/01 2017

1.0.0

1.0.0.0 https://github.com/chris48s/cakephp-searchable

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar chris48s

cakephp search mysql fulltext searchable