PHPackages                             scalia/sphinxsearch - 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. scalia/sphinxsearch

Abandoned → [sngrl/sphinxsearch](/?search=sngrl%2Fsphinxsearch)Library[Search &amp; Filtering](/categories/search)

scalia/sphinxsearch
===================

Laravel package to query Sphinxsearch

0.2(11y ago)16453.4k48[3 PRs](https://github.com/scalia/sphinxsearch/pulls)Apache-2.0PHPPHP &gt;=5.3.0

Since Apr 29Pushed 7y ago13 watchersCompare

[ Source](https://github.com/scalia/sphinxsearch)[ Packagist](https://packagist.org/packages/scalia/sphinxsearch)[ Docs](http://github.com/scalia/sphinxsearch)[ RSS](/packages/scalia-sphinxsearch/feed)WikiDiscussions master Synced yesterday

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

Sphinx Search
=============

[](#sphinx-search)

[![Build Status](https://camo.githubusercontent.com/37579754dcc0242e825e2878d26b9fa91825738b7dda0c9dee046f38101ffa33/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f7363616c69612f737068696e787365617263682e7376673f7374796c653d666c6174)](https://travis-ci.org/scalia/sphinxsearch)[![License](https://camo.githubusercontent.com/505a6bbf9bde8ad3085e790951f3cbccaa8cde5da6fcc3d9dda5156293d58a75/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363616c69612f737068696e787365617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/scalia/sphinxsearch)[![Latest Stable Version](https://camo.githubusercontent.com/c1c72d5e45a903b4d4dad0f2b38959959b1a2fa6221ef861ecdf3f6fdcc52c54/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363616c69612f737068696e787365617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/scalia/sphinxsearch)[![Total Downloads](https://camo.githubusercontent.com/f172ebe9b265b63353d75114b7832c29f714d87b1384e95a1188f79f2292a7da/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363616c69612f737068696e787365617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/scalia/sphinxsearch)[![Monthly Downloads](https://camo.githubusercontent.com/bb67a301bbfcb51bfa42dc71f075799b6da748b9a12a5e07aa60596e449c6c2a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f7363616c69612f737068696e787365617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/scalia/sphinxsearch)[![Stories in Ready](https://camo.githubusercontent.com/c778a5f7cb6e3189bdd29c96d8faf895baf9114f023181a14cc16f324a36f76e/68747470733a2f2f62616467652e776166666c652e696f2f7363616c69612f737068696e787365617263682e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/scalia/sphinxsearch)[![Stars](https://camo.githubusercontent.com/c74ce33cb800bec85780da88de9d6e0d074632e3a7b4e555b402fc487e3371e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7363616c69612f737068696e787365617263682e737667)](https://github.com/scalia/sphinxsearch/stargazers)[![Forks](https://camo.githubusercontent.com/c97ea5246f644eb03e978ec47e9fe60a3375a70507794caecbf2009a0703d59c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f7363616c69612f737068696e787365617263682e737667)](https://github.com/scalia/sphinxsearch/network)

Sphinx Search is a package for Laravel 4 which queries Sphinxsearch and integrates with Eloquent.

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

[](#installation)

Add `scalia/sphinxsearch` to `composer.json`.

```
"scalia/sphinxsearch": "dev-master"

```

Run `composer update` to pull down the latest version of Sphinx Search.

Now open up `app/config/app.php` and add the service provider to your `providers` array.

```
'providers' => array(
	'Scalia\SphinxSearch\SphinxSearchServiceProvider',
)
```

Now add the alias.

```
'aliases' => array(
	'SphinxSearch' => 'Scalia\SphinxSearch\SphinxSearchFacade',
)
```

Configuration
-------------

[](#configuration)

To use Sphinx Search, you need to configure your indexes and what model it should query. To do so, publish the configuration into your app.

```
php artisan config:publish scalia/sphinxsearch
```

This will create the file `app/config/packages/scalia/sphinxsearch/config.php`. Modify as needed the host and port, and configure the indexes, binding them to a table and id column.

```
return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
		'my_index_name' => array ( 'table' => 'my_keywords_table', 'column' => 'id' ),
	)
);
```

Or disable the model querying to just get a list of result id's.

```
return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
		'my_index_name' => FALSE,
	)
);
```

Usage
-----

[](#usage)

Basic query (raw sphinx results)

```
$results = SphinxSearch::search('my query')->query();
```

Basic query (with Eloquent)

```
$results = SphinxSearch::search('my query')->get();
```

Query another Sphinx index with limit and filters.

```
$results = SphinxSearch::search('my query', 'index_name')
	->limit(30)
	->filter('attribute', array(1, 2))
	->range('int_attribute', 1, 10)
	->get();
```

Query with match and sort type specified.

```
$result = SphinxSearch::search('my query', 'index_name')
	->setFieldWeights(
		array(
			'partno'  => 10,
			'name'    => 8,
			'details' => 1
		)
	)
	->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED)
	->setSortMode(\Sphinx\SphinxClient::SPH_SORT_EXTENDED, "@weight DESC")
	->get(true);  //passing true causes get() to respect returned sort order
```

Query and sort with geo-distant searching.

```
$radius = 1000; //in meters
$latitude = deg2rad(25.99);
$longitude = deg2rad(-80.35);
$result = SphinxSearch::search('my_query', 'index_name')
	->setSortMode(\Sphinx\SphinxClient::SPH_SORT_EXTENDED, '@geodist ASC')
	->setFilterFloatRange('@geodist', 0.0, $radius)
	->setGeoAnchor('lat', 'lng', $latitude, $longitude)
	->get(true);
```

Integration with Eloquent
-------------------------

[](#integration-with-eloquent)

This package integrates well with Eloquent. You can change index configuration with `modelname` to get Eloquent's Collection (Illuminate\\Database\\Eloquent\\Collection) as a result of `SphinxSearch::search`.

```
return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
		'my_index_name' => array ( 'table' => 'my_keywords_table', 'column' => 'id', 'modelname' => 'Keyword' ),
	)
);
```

Eager loading with Eloquent is the same an one would expect:

```
$results = SphinxSearch::search('monkeys')->with('arms', 'legs', 'otherLimbs')->get();
```

More on eager loading:

Paging results in Laravel 4 (with caching)
------------------------------------------

[](#paging-results-in-laravel-4-with-caching)

```
Route::get('/search', function ()
{
    $page = Input::get('page', 1);
    $search = Input::get('q', 'search string');
    $perPage = 15;  //number of results per page
    // use a cache so you dont have to keep querying sphinx for every page!
    $results = Cache::remember(Str::slug($search), 10, function () use($search)
    {
        return SphinxSearch::search($search)
        ->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED2)
        ->get();
    });
    if ($results) {
    	$totalItems = $results->count();
        $pages = array_chunk($results->all(), $perPage);

        $paginator = Paginator::make($pages[$page - 1], $totalItems, $perPage);
        return View::make('searchpage')->with('data', $paginator);
    }
    return View::make('notfound');
});
```

Paging results in Laravel 4 (without caching)
---------------------------------------------

[](#paging-results-in-laravel-4-without-caching)

```
Route::get('/search', function ()
{
    $page = Input::get('page', 1);
    $search = Input::get('q', 'search string');
    $perPage = 15;  //number of results per page
    $items = null;

    $results = SphinxSearch::search($search)
        ->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED2)
        ->limit($perPage, ($page-1)* $perPage)
        ->get();

    if (!empty($results['total'])) {
        $items = Item::whereIn('id', array_keys($results['matches']))->get();
        $items = Paginator::make($items->all(), $results['total'], $perPage);

        $items->appends(['search' => $search]); //add search query string
    }

    if($error = SphinxSearch::getErrorMessage())
    {
        //
    }
});
```

And, in your view after you finish displaying rows,

```

```

Searching through multiple Sphinx indexes (main/delta)
------------------------------------------------------

[](#searching-through-multiple-sphinx-indexes-maindelta)

It is a common strategy to utilize the main+delta scheme ([www.sphinxconsultant.com/sphinx-search-delta-indexing/](http://www.sphinxconsultant.com/sphinx-search-delta-indexing/)). When using deltas, it is often necessary to query on multiple indexes simultaneously. In order to achieve this using SphinxSearch, modify your config file to include the "name" and "mapping" keys like so:

```
return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
	    'name'    => array ('main', 'delta'),
	    'mapping' => array ( 'table' => 'properties', 'column' => 'id' ),
	)
);
```

You can also pass in multiple indexes (separated by comma or space) to your search like so (if the "mapping" key is not specified in the config, search retrieves ids):

```
SphinxSearch::search('lorem', 'main, delta')->get();
```

Retrieve search result excerpts using Sphinx
--------------------------------------------

[](#retrieve-search-result-excerpts-using-sphinx)

It is nifty to display excerpts with keywords highlighted in search result. Sphinx supports this feature natively.

```
$search = SphinxSearch::search($term, 'articles');
$articles = $search->get();
$excerpt = $search->excerpt(current($articles)->content);

or

$search = SphinxSearch::search($term, 'articles');
dd($search->excerpts(array_pluck($articles, 'content')));
```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

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

Total

3

Last Release

4112d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/380056?v=4)[Antonio Nicolás Pina](/maintainers/ANPez)[@anpez](https://github.com/anpez)

![](https://avatars.githubusercontent.com/u/352689?v=4)[Daniel Vigueras](/maintainers/dvigueras)[@dvigueras](https://github.com/dvigueras)

---

Top Contributors

[![anpez](https://avatars.githubusercontent.com/u/380056?v=4)](https://github.com/anpez "anpez (8 commits)")[![brianmcdo](https://avatars.githubusercontent.com/u/2156475?v=4)](https://github.com/brianmcdo "brianmcdo (4 commits)")[![alpha0010](https://avatars.githubusercontent.com/u/4990928?v=4)](https://github.com/alpha0010 "alpha0010 (2 commits)")[![levi730](https://avatars.githubusercontent.com/u/154903?v=4)](https://github.com/levi730 "levi730 (2 commits)")[![aabidos](https://avatars.githubusercontent.com/u/1707359?v=4)](https://github.com/aabidos "aabidos (2 commits)")[![tjoelsson](https://avatars.githubusercontent.com/u/2793514?v=4)](https://github.com/tjoelsson "tjoelsson (1 commits)")[![tmajne](https://avatars.githubusercontent.com/u/7447603?v=4)](https://github.com/tmajne "tmajne (1 commits)")[![waffle-with-pears](https://avatars.githubusercontent.com/u/8701611?v=4)](https://github.com/waffle-with-pears "waffle-with-pears (1 commits)")[![Gawdl3y](https://avatars.githubusercontent.com/u/279900?v=4)](https://github.com/Gawdl3y "Gawdl3y (1 commits)")[![qsun](https://avatars.githubusercontent.com/u/136623?v=4)](https://github.com/qsun "qsun (1 commits)")[![silentred](https://avatars.githubusercontent.com/u/3345293?v=4)](https://github.com/silentred "silentred (1 commits)")[![smitp](https://avatars.githubusercontent.com/u/761961?v=4)](https://github.com/smitp "smitp (1 commits)")

---

Tags

laravelLaravel 4sphinxsphinxsearch

### Embed Badge

![Health badge](/badges/scalia-sphinxsearch/health.svg)

```
[![Health](https://phpackages.com/badges/scalia-sphinxsearch/health.svg)](https://phpackages.com/packages/scalia-sphinxsearch)
```

PHPackages © 2026

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