PHPackages                             best-served-cold/laravel-zendsearch - 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. best-served-cold/laravel-zendsearch

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

best-served-cold/laravel-zendsearch
===================================

ZendSearch implementation for Laravel - Local file based search engine

1.0.6(9y ago)332MITPHPPHP &gt;=5.6.4

Since Oct 4Pushed 9y ago2 watchersCompare

[ Source](https://github.com/nark3d/LaravelZendSearch)[ Packagist](https://packagist.org/packages/best-served-cold/laravel-zendsearch)[ RSS](/packages/best-served-cold-laravel-zendsearch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/63673b7241a7897f203ff3c5f17ef6d2fb897c61024ca1938d8dbc81bff20038/68747470733a2f2f7472617669732d63692e6f72672f6e61726b33642f4c61726176656c5a656e645365617263682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nark3d/LaravelZendSearch)[![Build Status](https://camo.githubusercontent.com/a522fd5bd6c44e844e531651d514d4db97827a60c18717f1fb618fc566a1576f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e61726b33642f4c61726176656c5a656e645365617263682f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nark3d/LaravelZendSearch/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/ef49bc67607a09c47f7481f271abda206b78f3d11557156caa2be2b7daa4c755/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e61726b33642f4c61726176656c5a656e645365617263682f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nark3d/LaravelZendSearch/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/466556396f550f8fdbc1489f76332d1f136ba4d6a04755439059f73e81cb6bb2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e61726b33642f4c61726176656c5a656e645365617263682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nark3d/LaravelZendSearch/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/236be9a4aa67dbdebbc451472d63dbae45b7c4a18ca483f5eaa7f4138dc964c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626573742d7365727665642d636f6c642f6c61726176656c2d7a656e647365617263682e737667)](https://packagist.org/packages/best-served-cold/laravel-zendsearch)[![SensioLabsInsight](https://camo.githubusercontent.com/dccb973858c7eefcd12573f5fdb84704f8984c5516b86b801dd00e6361445cfc/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f64303432663661312d303837372d343431632d393262372d6262356665353164363436362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/d042f6a1-0877-441c-92b7-bb5fe51d6466)

LaravelZendSearch
=================

[](#laravelzendsearch)

A fast implementation of [ZendSearch](http://zf2.readthedocs.io/en/latest/tutorials/lucene.intro.html) hooking into Laravel eloquent. Utilise the power of Lucene without installing a secondary service such as Elasticsearch or Solr.

After using a couple of packages for [ZendSearch](http://zf2.readthedocs.io/en/latest/tutorials/lucene.intro.html) in Laravel I was disappointed with the performance, so I created my own.

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

[](#installation)

Follow these steps to get the package in place:

### Setup

[](#setup)

```
composer require best-served-cold/laravel-zendsearch
```

Update composer and then add the `ServiceProvider` to `config/app.php`:

```
'providers' => [
  // ...
	BestServedCold\LaravelZendSearch\Laravel\ServiceProvider::class,
],
```

I'm not keen on Facades, but if you want to use one, add it to the aliases in `config/app.php`:

```
'aliases' => [
   // ...
	'Search' => BestServedCold\LaravelZendSearch\Laravel\Facade::class,
],
```

### Publish

[](#publish)

Get your config published:

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

### Indexing

[](#indexing)

Add the `SearchTrait` and use it in the models you want to use:

```
// ...

use BestServedCold\LaravelZendSearch\Laravel\SearchTrait;

class User extends Model
{
    use SearchTrait;

// ...
```

Then add the method `searchFields()` and populate it with the fields you want to be indexed:

```
// ...
    public static function searchFields()
    {
        self::setSearchFields(['some', 'fields']);
    }
// ...
```

If you want to "boost" fields, then add the following method:

```
// ...
    public static function boostFields()
    {
        self::setBoostFields(['some' => 0.8, 'fields' => 1.0]);
    }
// ...
```

The index will build automatically from there.

#### Relations

[](#relations)

If you want to index relations, make sure you create your `getRelationAttribute()` method and then add the relation to the `protected $appends = [$relation];` array in your model.

### Building

[](#building)

If you have existing data or have changed your search fields, you can rebuild the index from scratch:

```
php artisan search:rebuild --verbose
```

Destroy:

```
php artisan search:destroy --verbose
```

Optimise:

```
php artisan search:optmise --verbose
```

I'll work on a scheduler in the near future, but make sure you optimise your index regularly. I'd suggest scheduling it yourself for now every hour or so.

Searching
---------

[](#searching)

### Basic

[](#basic)

Create a search instance:

```
$search = UserModel::search();

// add your query
$search->where('string', 'field');

// add an exact match
$search->match('string', 'field');

// Search all fields
$search->where('string');

// limit your query
$search->limit(10);

// get your hits (primary keys in an array)
$ids = $search->hits();

// and or, get your eloquent collection
$result = $search->get();

// Or chain it:
$result = User::search()->where('term', 'field')->limit(15)->offset(10)->get();
```

### Deleting

[](#deleting)

```
// Make sure you've got a collection like so
User::search()->where('term', 'field')->first()->delete();
```

### Advanced

[](#advanced)

```
$search = UserModel::search();

// Wildcard
$search->wildcard('ter*', 'field');

// Phrase
$search->phrase('this is the phrase', 'field', [1, 2, 3, 4]);

// Fuzzy
$search->fuzzy('term', 'field');

// Term
$search->term('complete_term', 'field');

// Get the last query
BestServedCold\LaravelZendSearch\Lucene\Search::getLastQuery()->__toString();
```

Filters
-------

[](#filters)

There are two basic filters implemented in the configuration which you can override, StopWords and ShortWords. You can, however, change both the filters and the analyzer manually to preset ZendSearch classes or custom classes:

```
BestServedCold\LaravelZendSearch\Lucene\Filter::setAnalyzer(
    new ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num\CaseInsensitive;
);

BestServedCold\LaravelZendSearch\Lucene\Filter::addFilter(
    new ZendSearch\Lucene\Analysis\TokenFilter\LowerCaseUtf8;
);
```

Helpers
-------

[](#helpers)

To assist in debugging, there are a few helpers which can assist:

```
// Returns the last ZendSearch\Lucene\Document inserted.
var_dump(BestServedCold\LaravelZendSearch\Lucene\Store::getLastInsert());

// Returns the current set of filters or analyzer
var_dump(BestServedCold\LaravelZendSearch\Lucene::getFilters());
var_dump(BestServedCold\LaravelZendSearch\Lucene::getAnalyzer());

// Returns the last ZendSearch\Lucene\Search\Query\Boolean object to interrogate.
var_dump(BestServedCold\LaravelZendSearch\Lucene::getLastQuery()->__toString());
```

Features to come
----------------

[](#features-to-come)

This is the first stable version which I've made mainly for my own use on another project. I will add the following in due course though.

- Scheduled optimisation out of the box
- Option passthrough added for Wildcard, Phrase, Fuzzy
- Add in highlighting options

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 92.6% 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 ~15 days

Recently: every ~30 days

Total

10

Last Release

3368d ago

Major Versions

0.1.2 → 1.0.02016-10-21

PHP version history (2 changes)0.1.0PHP &gt;=5.5.9

1.0.2PHP &gt;=5.6.4

### Community

Maintainers

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

---

Top Contributors

[![nark3d](https://avatars.githubusercontent.com/u/2162621?v=4)](https://github.com/nark3d "nark3d (150 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (12 commits)")

---

Tags

searchlaraveleloquentlucenezendsearchlocal search enginefile based search engine

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/best-served-cold-laravel-zendsearch/health.svg)

```
[![Health](https://phpackages.com/badges/best-served-cold-laravel-zendsearch/health.svg)](https://phpackages.com/packages/best-served-cold-laravel-zendsearch)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[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)[mohammad-fouladgar/eloquent-builder

527189.5k](/packages/mohammad-fouladgar-eloquent-builder)[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127259.1k5](/packages/jedrzej-searchable)

PHPackages © 2026

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