PHPackages                             carlosmaiello/search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. carlosmaiello/search

ActiveCakephp-plugin[Search &amp; Filtering](/categories/search)

carlosmaiello/search
====================

CakePHP 3.0 easy search framework

1.2.3(10y ago)066MITPHP

Since Jul 9Pushed 10y ago1 watchersCompare

[ Source](https://github.com/carlosmaiello/search)[ Packagist](https://packagist.org/packages/carlosmaiello/search)[ Docs](https://github.com/FriendsOfCake/search)[ RSS](/packages/carlosmaiello-search/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

CakePHP Search
==============

[](#cakephp-search)

[![Build Status](https://camo.githubusercontent.com/9b2dd3282c67993050f8093f643e30989bc34fde6b058317d205902f057c5d73/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f467269656e64734f6643616b652f7365617263682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/FriendsOfCake/search)[![Coverage Status](https://camo.githubusercontent.com/04b7e558b71058753369cd65223c2c0c8031c483d75816011d104de2a73f424a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f467269656e64734f6643616b652f7365617263682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/FriendsOfCake/search?branch=master)[![Total Downloads](https://camo.githubusercontent.com/b2dbe17449f562f68b9c9aef6fc4a89975e956c8ce752e1b8f41f6ffa7b301c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64736f6663616b652f7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friendsofcake/search)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friendsofcake/search)

Search provides a search module for CakePHP applications.

Requirements
------------

[](#requirements)

The master branch has the following requirements:

- CakePHP 3.0.0 or greater.

Installation
------------

[](#installation)

- Install the plugin with composer from your CakePHP Project's ROOT directory (where composer.json file is located)

```
php composer.phar require friendsofcake/search
```

- Load the plugin by adding following to your `config/bootstrap.php`

```
Plugin::load('Search');
```

or running command

```
./bin/cake plugin load Search
```

Usage
-----

[](#usage)

The plugin has three main parts which you will need to configure and include in your application.

### Table class

[](#table-class)

There are three tasks during setup in your table class. Firstly you must add a `use` statement for the `Search\Manager`. Next you need to attach the `Search`behaviour to your table class. Lastly you must add a `searchConfiguration`method to your table class so that you can configure how the search will work.

```
use Search\Manager;

class ExampleTable extends Table {

	public function initialize(array $config)
	{
		// Add the behaviour to your table
		$this->addBehavior('Search.Search');
	}

	// Configure how you want the search plugin to work with this table class
    public function searchConfiguration()
    {
        $search = new Manager($this)
            ->value('author_id', [
                'field' => $this->aliasField('author_id')
            ])
            // Here we will alias the 'q' query param to search the `Articles.title`
            // field and the `Articles.content` field, using a LIKE match, with `%`
            // both before and after.
            ->like('q', [
                'before' => true,
                'after' => true,
                'field' => [$this->aliasField('title'), $this->aliasField('content')]
            ])
            ->callback('foo', [
                'callback' => function ($query, $args, $manager) {
                    // Modify $query as required
                }
            ]);

        return $search;
    }
```

### Controller class

[](#controller-class)

In order for the Search plugin to work it will need to process the query params which are passed in your url. So you will need to edit your `index` method to accomodate this.

```
public function index()
{
    $query = $this->Articles
    	// Use the plugins 'search' custom finder and pass in the
    	// processed query params
        ->find('search', $this->Articles->filterParams($this->request->query))
        // You can add extra things to the query if you need to
        ->contain(['Comments'])
        ->where(['title IS NOT' => null]);

    $this->set('articles', $this->paginate($query));
}
```

The `search` finder and the `filterParams()` method are dynamically provided by the `Search` behavior.

### Component

[](#component)

Then add the Search Prg component to the necessary methods in your controller.

⚠️ Make sure,

- That you add this in the controller's `initialize()` method.
- That you only add this to methods which are using search, such as your `index()` method.

```
public function initialize()
{
    parent::initialize();

    if ($this->request->action === 'index') {
        $this->loadComponent('Search.Prg');
    }
}
```

The `Search.Prg` component will allow your filtering forms to be populated using the data in the query params. It uses the [Post, redirect, get pattern](https://en.wikipedia.org/wiki/Post/Redirect/Get).

Filtering your data
-------------------

[](#filtering-your-data)

Once you have completed all the setup you can now filter your data by passing query params in your index method. Using the `Article` example given above, you could filter your articles using the following.

`example.com/articles?q=cakephp`

Would filter your list of articles to any article with "cakephp" in the `title`or `content` field. You might choose to make a `get` form which posts the filter directly to the url, but if you're using the `Search.Prg` component, you'll want to use `POST`.

### Creating your form

[](#creating-your-form)

In most cases you'll want to add a form to your index view which will search your data.

```
    echo $this->Form->create();
    // You'll need to populate $authors in the template from your controller
    echo $this->Form->input('author_id');
    // Match the search param in your table configuration
    echo $this->Form->input('q');
    echo $this->Form->button('Filter', ['type' => 'submit']);
    echo $this->Html->link('Reset', ['action' => 'index']);
    echo $this->Form->end();
```

If you are using the `Search.Prg` component the forms current values will be populated from the query params.

Filters
-------

[](#filters)

The Search plugin comes with a set of predefined search filters that allow you to easily create the search results you need. Use:

- `value` to limit results to exact matches
- `like` to produce results containing the search query (`LIKE`)
- `finder` to produce results using a [(custom)](http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#custom-find-methods) finder
- `compare` to produce results requiring operator comparison ( `>`, `=` and `value('author_id', [
        'filterEmpty' => true
    ]);
```

Be sure to allow empty in your search form, if you're using one.

```
echo $this->Form->input('author_id', ['empty' => 'Pick an author']);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~35 days

Total

6

Last Release

3678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/122ddf761c1930e407cdf5a0a20a3f4570a5ea3ff1e465c07e97e413b53baf2c?d=identicon)[magrathea](/maintainers/magrathea)

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (35 commits)")[![jippi](https://avatars.githubusercontent.com/u/22841?v=4)](https://github.com/jippi "jippi (24 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (10 commits)")[![cake17](https://avatars.githubusercontent.com/u/1652972?v=4)](https://github.com/cake17 "cake17 (9 commits)")[![carlosmaiello](https://avatars.githubusercontent.com/u/3230041?v=4)](https://github.com/carlosmaiello "carlosmaiello (6 commits)")[![davidyell](https://avatars.githubusercontent.com/u/49889?v=4)](https://github.com/davidyell "davidyell (6 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (2 commits)")[![bravo-kernel](https://avatars.githubusercontent.com/u/230500?v=4)](https://github.com/bravo-kernel "bravo-kernel (2 commits)")[![steefaan](https://avatars.githubusercontent.com/u/5982785?v=4)](https://github.com/steefaan "steefaan (1 commits)")[![curtisgibby](https://avatars.githubusercontent.com/u/1086964?v=4)](https://github.com/curtisgibby "curtisgibby (1 commits)")[![AD7six](https://avatars.githubusercontent.com/u/33387?v=4)](https://github.com/AD7six "AD7six (1 commits)")

---

Tags

searchcakephpcakephp3cake3

### Embed Badge

![Health badge](/badges/carlosmaiello-search/health.svg)

```
[![Health](https://phpackages.com/badges/carlosmaiello-search/health.svg)](https://phpackages.com/packages/carlosmaiello-search)
```

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[solarium/solarium

PHP Solr client

93532.7M98](/packages/solarium-solarium)[friendsofcake/search

CakePHP Search plugin using PRG pattern

1742.0M37](/packages/friendsofcake-search)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[skie/cakephp-search

CakePHP Plum Search plugin

19186.5k2](/packages/skie-cakephp-search)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
