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

ActiveSymfony-bundle

xanderkon/sphinxsearch-bundle
=============================

Sphinx search bundle for Symfony 2

0.2.5(8y ago)2441MITPHPPHP &gt;=5.3.3

Since Sep 25Pushed 6y ago3 watchersCompare

[ Source](https://github.com/XanderKon/SphinxsearchBundle)[ Packagist](https://packagist.org/packages/xanderkon/sphinxsearch-bundle)[ Docs](https://github.com/IAkumaI/SphinxsearchBundle)[ RSS](/packages/xanderkon-sphinxsearch-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (8)Used By (0)

SphinxsearchBundle
==================

[](#sphinxsearchbundle)

With this bundle you can use Sphinx to search in your Symfony2 project.

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

[](#installation)

### Step 1: Download SphinxsearchBundle using composer

[](#step-1-download-sphinxsearchbundle-using-composer)

In your composer.json, add SphinxsearchBundle:

```
{
    "require": {
        "iakumai/sphinxsearch-bundle": "dev-master"
    }
}
```

Now, you must update your vendors using this command :

```
$ php composer.phar update iakumai/sphinxsearch-bundle
```

### Step 2: Add bundle in AppKernel.php

[](#step-2-add-bundle-in-appkernelphp)

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IAkumaI\SphinxsearchBundle\SphinxsearchBundle()
    );
}
```

### Step 3: Configure your config.yml

[](#step-3-configure-your-configyml)

By default bundle does not need to be a configured, but has some options for you.

**Full configuration :**

```
# app/config/config.yml
sphinxsearch:
    searchd:
        # Host name for your Sphinx daemon
        host: localhost
        # Port number for your Sphinx daemon
        port: 9312
        # If you want to connect via scoket
        socket: /path/to/socket.file
    indexes:
        # List of sphinx index names (key) and entity names (value)
        # to use it in searchEx() method
        IndexName: "Bundle:Entity"
```

Services
--------

[](#services)

- **@iakumai.sphinxsearch.search** - base search engine to use Sphinx search.

Maybe you want to use another class in **@iakumai.sphinxsearch.search** service. To do this put a full class name to the parameter named **%iakumai.sphinxsearch.search.class%**.

- **@iakumai.sphinxsearch.doctrine.bridge** - bridge to dictrine datebase.

Maybe you want to use another class in **@iakumai.sphinxsearch.doctrine.bridge** service. To do this put a full class name to the parameter named **%iakumai.sphinxsearch.doctrine.bridge.class%**. It must implements a `IAkumaI\SphinxsearchBundle\Doctrine\BridgeInterface`

Exceptions
----------

[](#exceptions)

- **EmptyIndexException** - you will see this exception if try to search without indexes.
- **NoSphinxAPIException** - this exception throws if not SphinxAPI was found.

Highlight search results
------------------------

[](#highlight-search-results)

You can highlight search words in templates by use **sphinx\_highlight** filter.

For example:

```

    {{ content|sphinx_highlight('IndexName', 'query word', {limit:100}) }}

```

In this example matches for **"query word"** in **content** variable will be highlighted for **IndexName** index. It use [BuildExcerpts](https://github.com/romainneutron/Sphinx-Search-API-PHP-Client/blob/master/sphinxapi.php#L1309) method for this.

Useful features
---------------

[](#useful-features)

### Sphinx search by date range

[](#sphinx-search-by-date-range)

For example, search link looks like [http://site.ru/search/?date-start=26.09.2013&amp;date-end=27.09.2013](http://site.ru/search/?date-start=26.09.2013&date-end=27.09.2013)

```
// ...
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class SearchController extends Controller
{
    public function indexAction(Request $request)
    {
        // Get a search service
        $sphinx = $this->get('iakumai.sphinxsearch.search');

        // Convert request parameters to \DateTime
        if ($datestart = $request->query->get('date-start')) {
            $datestart = \DateTime::createFromFormat('d.m.Y', $datestart);
        }

        if ($dateend = $request->query->get('date-end')) {
            $dateend = \DateTime::createFromFormat('d.m.Y', $dateend);
        }

        // Apply sphinx filter
        // updated - is a timestamp-attribute name in sphinx config
        $sphinx->setFilterBetweenDates('updated', $datestart, $dateend);

        return $sphinx->search($request->query->get('q', ''), array('IndexName'));
    }
}
```

Examples
--------

[](#examples)

This code will use IndexName index to search for a query in *q*-get parameter:

```
// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    return $sphinxSearch->search($request->query->get('q', ''), array('IndexName'));
}
```

You can use all methods, that provides by [PHP SphinxAPI](https://github.com/romainneutron/Sphinx-Search-API-PHP-Client).

For example:

```
// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    $searchd->setLimits(0, 100);
    return $sphinxSearch->search($request->query->get('q', ''), array('IndexName'));
}
```

Now bundle can auto convert search results to entities if you will search for one index or define a *index\_name* attribute in sphinx config. To to this, first configure index names, for example:

```
# app/config/config.yml
sphinxsearch:
    indexes:
        IndexName: "Bundle:Entity"
```

To convert multiple queries please add *index\_name* attribute to your sphinx.conf file, for example:

```
source Example
{
    sql_query = SELECT id, ...., 'IndexName' as 'index_name' FROM my_table
    sql_attr_string = index_name
}

index IndexName
{
    source = Example
    path = /your/own/path
}

```

Now you can execute searchEx() method:

```
// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    $results_one = $sphinxSearch->searchEx($request->query->get('q', ''), 'IndexName');
    // or for multiple indexes (index_name attribute must exists)
    $results_two = $sphinxSearch->searchEx($request->query->get('q', ''), array('IndexName', 'SeconIndexName'));
}
```

**$results\_one** now will contains something like this:

```
array(10) {
  .....
  ["matches"]=>
  array(20) {
    [22]=>
    array(3) {
      ["weight"]=>
      string(1) "2"
      ["attrs"]=>
      array(0) {
      }
      ["entity"]=> ... // Here is your Bundle:Entity
    }
    .........

```

**$results\_two** now will contains something like this:

```
array(10) {
  .....
  ["matches"]=>
  array(20) {
    [22]=>
    array(3) {
      ["weight"]=>
      string(1) "2"
      ["attrs"]=>
      array(0) {
        ["index_name"]=>
        string(9) "IndexName"
      }
      ["entity"]=> ... // Here is your Bundle:Entity
    }
    .........

```

### Pagerfanta adapter

[](#pagerfanta-adapter)

This bundle also includes special adapter for excellent [Pagerfanta bundle](https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle)

```
/** @var $sphinx \IAkumaI\SphinxsearchBundle\Search\Sphinxsearch */
$sphinx = $this->get('iakumai.sphinxsearch.search');

/** @var $sphinxDoctrineBridge \IAkumaI\SphinxsearchBundle\Doctrine\Bridge */
$sphinxDoctrineBridge = $this->get('iakumai.sphinxsearch.doctrine.bridge');
$sphinx->setBridge($sphinxDoctrineBridge); //IMPORTANT! Set doctrine bridge.

$query = 'search query';
$entityIndexType = 'Books';

$adapter = new \IAkumaI\SphinxsearchBundle\Pagerfanta\Adapter\SphinxSearchAdapter($sphinx, $query, $entityIndexType, [
    'max_results' => 1000000,
]);
$pager = new Pagerfanta($adapter);
// Use pagerfanta as always
...
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83% 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 ~319 days

Recently: every ~399 days

Total

6

Last Release

3013d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23970cfac2237e6ec32f957409f8e73f6315d8972b091140f6f1f0c5a85ccc99?d=identicon)[Xander](/maintainers/Xander)

---

Top Contributors

[![IAkumaI](https://avatars.githubusercontent.com/u/907560?v=4)](https://github.com/IAkumaI "IAkumaI (39 commits)")[![XanderKon](https://avatars.githubusercontent.com/u/16461100?v=4)](https://github.com/XanderKon "XanderKon (5 commits)")[![iVariable](https://avatars.githubusercontent.com/u/427486?v=4)](https://github.com/iVariable "iVariable (2 commits)")[![averichev](https://avatars.githubusercontent.com/u/5820708?v=4)](https://github.com/averichev "averichev (1 commits)")

---

Tags

Symfony2sphinxsphinxsearch

### Embed Badge

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

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

###  Alternatives

[iakumai/sphinxsearch-bundle

Sphinx search bundle for Symfony 2

29204.4k](/packages/iakumai-sphinxsearch-bundle)[search/sphinxsearch-bundle

Sphinx search bundle for Symfony 2

4113.0k](/packages/search-sphinxsearch-bundle)[javer/sphinx-bundle

Provides integration of Sphinx search engine with Symfony using SphinxQL

24185.4k](/packages/javer-sphinx-bundle)

PHPackages © 2026

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