PHPackages                             faithfm/smart-search-php - 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. [Templating &amp; Views](/categories/templating)
4. /
5. faithfm/smart-search-php

ActiveLibrary[Templating &amp; Views](/categories/templating)

faithfm/smart-search-php
========================

Search/filter using simple Google-style search strings to perform complex filter operations.

2.4.1(2y ago)93.3kGPL-3.0-or-laterPHPPHP ^7.2|^8.0

Since Feb 27Pushed 2y ago2 watchersCompare

[ Source](https://github.com/faithfm/smart-search-php)[ Packagist](https://packagist.org/packages/faithfm/smart-search-php)[ Docs](https://github.com/faithfm/smart-search-php)[ RSS](/packages/faithfm-smart-search-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (19)Used By (0)

smart-search-php
================

[](#smart-search-php)

Simple (yet powerful) PHP search/filter providing unified results in multiple contexts:

- MySQL/other databases (ie: "where" clause builder)
- PHP arrays
- Laravel Collections
- Laravel Models
- Laravel Nova Resources

Simple Google-style search strings perform complex filter operations across multiple fields.

(PHP backend equivalent of [`miking/smart-search-filter`](https://github.com/miking7/smart-search-filter) javascript library JS library)

Screenshot:
-----------

[](#screenshot)

[![smart-search-01.jpg](docs/smart-search-01.jpg)](docs/smart-search-01.jpg)

Installation:
-------------

[](#installation)

Require this package in the `composer.json` of your project.

```
composer require faithfm/smart-search-php
```

> Note: an [additional dependency](docs/wherenot-dependency.md) must be manually installed for **Laravel** Models &amp; Nova Resources. (Applies to Laravel &lt;= 8.x)

Usage Examples:
---------------

[](#usage-examples)

Start by creating an instance of `SmartSearch` with the **search string**, and a list of **default search fields**:

```
use FaithFM\SmartSearch\SmartSearch;

$search = 'optus 320 location:stock -F2701';
$smartSearch = new SmartSearch($search, 'asset_id|location|type|make|model|identifier');
```

The parsed search-string can now be used to perform filtering in one or more contexts:

- Context 1 - [PHP Array](docs/c1-arrays.md) filtering:

```
$filtered = $smartSearch->filterArray($items));
```

- Context 2 - [Laravel Collection](docs/c2-laravel-collections.md) filtering:

```
$filteredCollection = $smartSearch->filterCollection($myCollection));
```

- Context 3 - [SQL Database where-clause](docs/c3-sql-database.md) filtering:

```
$whereClause = $smartSearch->getSqlFilter());
```

- Context 4 - [Laravel Database Query Builder](docs/c4-laravel-db-builder.md) (DB or Model) filtering:

```
$data = DB::table('my_table')::where($smartSearch->getBuilderFilter())->get();
// OR
$data = MyModel::where( $smartSearch->getBuilderFilter() )->get();
```

- Context 5 - [Laravel Eloquent Model](docs/c5-laravel-eloquent-models.md) filtering:

```
MyModel::smartSearch('joe', 'location|type')->get();
```

- Context 6 - [Laravel Nova Resource](docs/c6-laravel-nova-resources.md) filtering: *(ie: as shown in the screenshot above)*

```
class MyResource extends Resource
{
    use SmartSearchableNovaResource;
    ...
```

Search Syntax:
--------------

[](#search-syntax)

The related [`miking/smart-search-filter`](https://github.com/miking7/smart-search-filter) javascript library includes [documentation](https://github.com/miking7/smart-search-filter#example) of how a simple Google-style search syntax is used to perform complex filter operations across multiple fields.

Note: Used together these two libraries provide a simple, unified, yet powerful approach to front-end/back-end filtering in modern web applications.

Debug Information:
------------------

[](#debug-information)

Under the hood, a "filter operations" array is created when a search string is parsed.
The `getFilterOpsDescription()` function provides a human-readable representation showing the parsed intent of the search string, and parsing errors are also available:

```
var_dump($smartSearch->errors);
var_dump($smartSearch->getFilterOpsDescription());
```

Advanced Options:
-----------------

[](#advanced-options)

The above examples have demonstrated the simple case where only two arguments are provided to the `SmartSearch` constructor, however a number of other advanced options are also available.

```
new SmartSearch($searchString, $defaultFields = "", $allowedFields = "", $options = [], Closure $sqlEscapeStringFn = null)
```

Notes:

- `$allowedFields` are the same as `$defaultFields` if not specified explicitly.
- Fields lists can be specified in a many different ways:

```
$defaultFields = 'location,type';       // comma-separated
$defaultFields = 'location, type';      // comma-separated (with spaces)
$defaultFields = 'location|type';       // pipe-separated
$defaultFields = ['location', 'type'];  // array format
//... and pretty much anything else that can be cast to an array (of strings)
```

- The `$options` parameter accepts an associative array or StdClass object and allows things like case sensitivity and sql wildcard characters to be defined. Default options are:

```
const DEFAULT_OPTIONS = [
    'caseSensitive' => false,
    'sqlWildcard' => '%',
    'sqlWildcardSingleChar' => '_',
];
```

> Note: all filters are currently case-insensitive. The `caseSensitive` option does not currently work.

- The `$sqlEscapeStringFn` can be specified in the constructor instead of calling `setSqlEscapeStringFn()` later.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 77.8% 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 ~35 days

Recently: every ~109 days

Total

18

Last Release

924d ago

Major Versions

1.6.0 → 2.0.02022-06-05

PHP version history (2 changes)1.0.0PHP ^7.2

2.1.0PHP ^7.2|^8.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/29ec36050b27f6835414c1a11c7b8b1121a0725dcf3c6a9a45104b336529c926?d=identicon)[lidiaordonez](/maintainers/lidiaordonez)

---

Top Contributors

[![miking7](https://avatars.githubusercontent.com/u/5072816?v=4)](https://github.com/miking7 "miking7 (7 commits)")[![lidiaordonez](https://avatars.githubusercontent.com/u/52942074?v=4)](https://github.com/lidiaordonez "lidiaordonez (2 commits)")

---

Tags

composerpackagetemplate

### Embed Badge

![Health badge](/badges/faithfm-smart-search-php/health.svg)

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

PHPackages © 2026

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