PHPackages                             pahanini/yii2-refiner - 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. [Database &amp; ORM](/categories/database)
4. /
5. pahanini/yii2-refiner

ActiveYii2-extension[Database &amp; ORM](/categories/database)

pahanini/yii2-refiner
=====================

Helps to add additional where params to active query (refine query)

v0.6(11y ago)86715[1 issues](https://github.com/pahanini/yii2-refiner/issues)BSD-3-ClausePHP

Since May 15Pushed 11y ago3 watchersCompare

[ Source](https://github.com/pahanini/yii2-refiner)[ Packagist](https://packagist.org/packages/pahanini/yii2-refiner)[ Docs](https://github.com/pahanini/yii2-refiner)[ RSS](/packages/pahanini-yii2-refiner/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Yii2 search refiner (facet search)
==================================

[](#yii2-search-refiner-facet-search)

Helps to add additional 'where' conditions based on http request to active queries (refine search queries) and also automates calculation of possible values of different filters used to build UI. Can be used in RESTful APIs.

Terms
-----

[](#terms)

"Base query" - ActiveQuery (e.g. MySqlQuery, SphinxQuery) to find all possible items before any refiner will be applied. E.g. `SELECT * FROM products WHERE balance > 0`

"Refiner" is object which:

- calculates all possible (or independent) values for UI, e.g. list of possible product's categories, maximum and minimum price between products (all callback).
- analyzes http request and add additional where conditions to basic query (refine callback)
- calculates active values of UI. Active values depends on values of other refiners (active callback).

"Refiner Set" - object which contain one or more refiners and base query. Refiner set applies all refiners to query.

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

[](#installation)

Add

`"pahanini/yii2-refiner": "*"`

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Set

[](#set)

Refiner set has two main independent functions:

- getRefinedQuery - returns query modified by refiners
- getRefinerValues - returns all refiners values

### Refiner

[](#refiner)

Each refiner modifies base query according to http query params. To modify query refiner calls `refine($query, $params)`callback function. This function must return modified query. Function example:

```
$this->refine = function($query, $params) {
    return $query->andWhere('has_discount > :val', [':val' => $params]);
}

```

Note:

- if http param does no exist refine function will not be called
- if $paramSeparator property is set and http param is not an array then http param wll converted to array using $paramSeparator property
- if $paramToArray property is set and http param is not an array then it will converted to array with one element
- if $paramType is set then http param type will be changed using php setType function

Some examples:

```
public function init()
{
	$this->refinerSet = new \pahanini\refiner\Set([
		'refiners' => [
			// standard range
			'price' => [
				'class' => '\pahanini\refiner\db\Range',
			],
			'category' => [
				'class' => '\pahanini\refiner\db\Count',
			],
			// Select color values from another model
			'onlyRedColor' => [
			    'refine' => function($query, $param) {
			        return $query->andWhere('color = "red"');
			    },
			    'all' => function($query) {
			        return $query->select('COUNT(*)')->andWhere('color = "red"')
			    }
			]
		]
	])
}

public function actionSearch()
{
	$query = Product::find()->andWhere('balance > 0');
	$refinerResult = $this->refinerSet->applyTo($query);
	$this->render('search', ['query' => $query, 'refiners' => $this->refinerSet->getRefinerValues()])
}

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~10 days

Total

6

Last Release

4325d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2ff5824ce711862778444b44442b7ae3b4aa7f1804a29da2c5ad375aecb5448?d=identicon)[pahanini](/maintainers/pahanini)

---

Top Contributors

[![pahanini](https://avatars.githubusercontent.com/u/898663?v=4)](https://github.com/pahanini "pahanini (30 commits)")

---

Tags

yii2facet searchrefine search

### Embed Badge

![Health badge](/badges/pahanini-yii2-refiner/health.svg)

```
[![Health](https://phpackages.com/badges/pahanini-yii2-refiner/health.svg)](https://phpackages.com/packages/pahanini-yii2-refiner)
```

###  Alternatives

[voskobovich/yii2-linker-behavior

This behavior makes it easy to maintain many-to-many and one-to-many relations in your ActiveRecord models.

80319.0k9](/packages/voskobovich-yii2-linker-behavior)[mootensai/yii2-relation-trait

Yii 2 Models load with relation, &amp; transaction save with relation

47220.3k9](/packages/mootensai-yii2-relation-trait)[nhkey/yii2-activerecord-history

Storage history of changes to ActiveRecord

46143.4k1](/packages/nhkey-yii2-activerecord-history)[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[spanjeta/yii2-backup

Database Backup and Restore functionality

285.0k1](/packages/spanjeta-yii2-backup)[craftcms/query

Execute database queries from the Control Panel

1614.5k1](/packages/craftcms-query)

PHPackages © 2026

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