PHPackages                             johnsnook/yii2-parsel - 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. johnsnook/yii2-parsel

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

johnsnook/yii2-parsel
=====================

Allows developers to provide a search query interface similar to Sphinx

v1.0.0(7y ago)31.4k↓71.7%[1 issues](https://github.com/johnsnook/yii2-parsel/issues)GPL-3.0+PHP

Since Jul 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/johnsnook/yii2-parsel)[ Packagist](https://packagist.org/packages/johnsnook/yii2-parsel)[ RSS](/packages/johnsnook-yii2-parsel/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Yii2 Parsel
===========

[](#yii2-parsel)

Allows developers to provide a boolean search query interface, similar to Google or Sphinx search or other full-text search (FTS) engines.

Turns a user query like '`georgia -(atlanta or decatur)`' into '`georgia AND NOT (atlanta or decatur)`' which is then turn into the follow SQL:

```
SELECT
  "ip", /* ip address */
  "visits", /* how many requests they've made */
  "city",
  "region"
FROM
/* A table similar to apaches access log.  See my extension yii2-ipFilter */
  "visitor"
WHERE
  (
    ("visitor"."ip" ILIKE '%georgia%')
    OR ("visitor"."city" ILIKE '%georgia%')
    OR ("visitor"."region" ILIKE '%georgia%')
  )
  AND ( /** marvel as we efortlessly generate a subquery */
    "ip" NOT IN (
      SELECT
        "ip"
      FROM
        "visitor"
      WHERE
        (
          ("visitor"."ip" ILIKE '%atlanta%')
          OR ("visitor"."city" ILIKE '%atlanta%')
          OR ("visitor"."region" ILIKE '%atlanta%')
        )
        OR (
          ("visitor"."ip" ILIKE '%decatur%')
          OR ("visitor"."city" ILIKE '%decatur%')
          OR ("visitor"."region" ILIKE '%decatur%')
        )
    )
  )
```

Example results:

IpVisitsCityRegion107.77.232.21616Georgia107.77.235.1993Georgia174.218.142.271LawrencevilleGeorgia107.77.233.22518Georgia205.201.132.1442WoodstockGeorgia192.3.160.154DouglasGeorgiaInstallation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist johnsnook/yii2-parsel "*"

```

or add

```
"johnsnook/yii2-parsel": "*"

```

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

Usage
-----

[](#usage)

> *"Look, I didn't know I could speak Parseltongue! What else don't I know about myself? Look. Maybe you can do something, even something horrible and not know you did it."*

Once the extension is installed, simply use it in your code by :

```
$userQuery = 'good AND plenty -licorice';
$parsel = new ParselQuery([
            'userQuery' => $this->userQuery,
            'dbQuery' => Script::find()
        ]);
$parsel->dbQuery->all();
```

Tokens/behavior:
----------------

[](#tokensbehavior)

Fields to be search must be either text, varchar or char currently. Future versions may expand to number, dates and maybe even JSON. All search terms, except where specified bye the full match operator are wrapped in your databases wildcard of choice. Searching for "smart" is equivalent to the SQL expression `'%smart%'`. Search is case insensitive as long as your database's `LIKE` operator is. PostgreSQL will use `ILIKE`.

#### Conjunctives:

[](#conjunctives)

'AND' is the default behavior. "smart pretty" is the same as "smart AND pretty."

'OR' allows more results in your query: "smart OR pretty."

#### Operators:

[](#operators)

OperatorTypeDescription-NegationThe user query "smart pretty -judgmental" parses to "smart AND pretty AND NOT judgmental"()Sub-queryAllows grouping of terms . The user query "-crazy (smart AND pretty)" parses to "NOT crazy AND (smart AND pretty)"\*WildcardFuzzy matches. "butt\*" matches butt, buttery, buttered etc.\_Character wildcardMatches one character. "boo\_" matches boot, book, bool, boon, etc.=Full matchEntire fields must be equal to the term. "=georgia" only matches where one or more fields is exactly equal to the search term. The search term will NOT be bracketed with %, but wildcards can still be used.""Double quotesPhrase. '"Super fun"' searches for the full phrase, space include. Wild cards, negation and exact match operators all work within the phrase.''Single quotesPhrase, no wildcards. The term will not be evaluated for \* or \_, but will be wrapped in wildcards. If a % or \_ is in the term, it will be escaped. 'P%on\*' becomes '%P%on\*%'.:FieldSpecify the field to search. 'name:jo\*' will search the name field for 'jo\*.' If no field name matches, all fields will be searched for 'name:jo\*'#### Examples

[](#examples)

See files in /examples. If it's still up, you might also be able to play with an example [here](https://snooky.biz/parsel)

#### Additional Reading

[](#additional-reading)

**PostgreSQL**

[Faster PostgreSQL Searches with Trigrams](http://blog.scoutapp.com/articles/2016/07/12/how-to-make-text-searches-in-postgresql-faster-with-trigram-similarity)

[Optimizing databases for fuzzy searching](https://stackoverflow.com/a/13452528)

**MySQL**

[Performance analysis of MySQL's FULLTEXT indexes and LIKE queries for full text search](https://makandracards.com/makandra/12813-performance-analysis-of-mysql-s-fulltext-indexes-and-like-queries-for-full-text-search)

Acknowledgements
----------------

[](#acknowledgements)

This project was built by heavily modifying the excellent "[Search Query Parser](https://github.com/pimcore/search-query-parser)" project. I de-abstracted the token structure and modified the parser class to better fit my needs. Their licsence file should be found at the root of this project.

Both projects are made possible by the amazing and lightning quick [lexer library](https://github.com/nikic/Phlexy) by Nikita Popov of Berlin. It's work reading his [article on the subject](http://nikic.github.io/2011/10/23/Improving-lexing-performance-in-PHP.html).

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Unknown

Total

1

Last Release

2899d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4065107?v=4)[John Snook](/maintainers/johnsnook)[@johnsnook](https://github.com/johnsnook)

---

Top Contributors

[![johnsnook](https://avatars.githubusercontent.com/u/4065107?v=4)](https://github.com/johnsnook "johnsnook (25 commits)")

---

Tags

searchqueryparseyii2extension

### Embed Badge

![Health badge](/badges/johnsnook-yii2-parsel/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[vintage/yii2-search

Search in Active Record models for Yii2

294.6k](/packages/vintage-yii2-search)[thrieu/yii2-grid-view-state

Save filters from GridView to session, keep the filter state between pages.

1313.7k1](/packages/thrieu-yii2-grid-view-state)[keygenqt/yii2-autocomplete-ajax

A simple way to search model id of the attributes model

1016.4k](/packages/keygenqt-yii2-autocomplete-ajax)[vxm/yii2-searchable

Simple full-text search for Yii2 active record

181.4k](/packages/vxm-yii2-searchable)

PHPackages © 2026

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