PHPackages                             duncanogle/boolean-search-parser - 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. duncanogle/boolean-search-parser

ActiveLibrary[Database &amp; ORM](/categories/database)

duncanogle/boolean-search-parser
================================

A way to translate Boolean Search logic into MySQL Fulltext Parameters

1.0.5(10y ago)721.6k3[2 issues](https://github.com/DuncanOgle/BooleanSearchParser/issues)[1 PRs](https://github.com/DuncanOgle/BooleanSearchParser/pulls)unlicensePHPPHP &gt;=5.4.0

Since Oct 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/DuncanOgle/BooleanSearchParser)[ Packagist](https://packagist.org/packages/duncanogle/boolean-search-parser)[ RSS](/packages/duncanogle-boolean-search-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

BooleanSearchParser
===================

[](#booleansearchparser)

[![Build Status](https://camo.githubusercontent.com/e50b0b2cb42995fbd4e75e54b0b46ad66cf81a86f74f7c68ffd7c14cc7faaf18/68747470733a2f2f7472617669732d63692e6f72672f44756e63616e4f676c652f426f6f6c65616e5365617263685061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DuncanOgle/BooleanSearchParser)

The aim of this class is to take a Boolean Search and to convert it into something that can be used in a MySQL Fulltext Search.

The idea came about after recently working a lot with Boolean Search systems, and after reading [this StackOverflow question](http://stackoverflow.com/questions/16016723/is-there-a-good-php-library-available-to-parse-boolean-search-operators-to-mysql), nothing really exists out there for MySQL.

Big thanks goes to [PHP SQL Parser](https://github.com/soundintheory/php-sql-parser) for having such a lovely Tokeniser and related methods, which made this easier.

Goals
-----

[](#goals)

- To provide a good-enough conversion
- To not try and correct mistakes with brackets and quotes etc.

Notes
-----

[](#notes)

### Use

[](#use)

```
$parser = new \DuncanOgle\BooleanSearchParser\Parser();

echo $parser->parse("ict OR (technology AND bob)");
// ict (+technology +bob)

```

### Regarding order

[](#regarding-order)

Order and brackets are important, more often than not OR logic takes priority

`sales OR finance AND manager` will become `sales finance +manager` and not `sales +finance +manager`

Todo
----

[](#todo)

- Handle the \* character
- Turn into a package that can be pulled in via composer
- Move tests over to PHP Unit
- Add custom priority settings (currently its OR&gt;AND&gt;NOT)
- Add optional word stemmer [like the one used here](https://github.com/ovaistariq/FULLTEXT-search-utility)

Simple Examples
---------------

[](#simple-examples)

InputOutput`ict``+ict``ict it``+ict +it``ict OR it``ict it``NOT ict``-ict``it NOT ict``+it -ict``web AND (ict OR it)``+web +(ict it)``ict OR (it AND web)``ict (+it +web)``ict NOT (ict AND it AND web)``+ict -(+ict +it +web)``php OR (NOT web NOT embedded ict OR it)``php (-web -embedded ict it)``(web OR embedded) (ict OR it)``+(web embedded) +(ict it)``develop AND (web OR (ict AND php))``+develop +(web (+ict +php))``"ict``null ``"ict OR it"``+"ict OR it"`Complex Examples
----------------

[](#complex-examples)

InputOutput`"business development" or "it sales" and (danish or dutch or italian or denmark or holland or netherlands or italy)``"business development" "it sales" +(danish dutch italian denmark holland netherlands italy)``(procurement or buying or purchasing) and (marine or sea) and (engineering or engineer)``+(procurement buying purchasing) +(marine sea) +(engineering engineer)`

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

3772d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ef3357c870eb980e294afaeebb496c0f14fda6006284ac2ec7c82949f29b463?d=identicon)[DuncanOgle](/maintainers/DuncanOgle)

---

Tags

searchmysqlfulltextlogicboolean

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/duncanogle-boolean-search-parser/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[baril/sqlout

MySQL fulltext driver for Laravel Scout.

4512.9k](/packages/baril-sqlout)[swissup/module-search-mysql-legacy

Legacy mysql search for magento 2.4

10483.0k](/packages/swissup-module-search-mysql-legacy)[nqxcode/laravel-lucene-search

Laravel 5.5 package for full-text search over Eloquent models based on ZendSearch Lucene.

7216.5k](/packages/nqxcode-laravel-lucene-search)[provision/searchable

Searchable indexing with MySQL full text for Laravel

228.4k](/packages/provision-searchable)

PHPackages © 2026

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