PHPackages                             ripaclub/zf2-sphinxsearch-tool - 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. ripaclub/zf2-sphinxsearch-tool

ActiveLibrary[Search &amp; Filtering](/categories/search)

ripaclub/zf2-sphinxsearch-tool
==============================

Utility that provides a set of tools to create and handle Sphinx Search configs and data sources

0.9.1(11y ago)33311[9 issues](https://github.com/ripaclub/zf2-sphinxsearch-tool/issues)1BSD-3-ClausePHPPHP &gt;=5.4

Since Jun 7Pushed 10y ago2 watchersCompare

[ Source](https://github.com/ripaclub/zf2-sphinxsearch-tool)[ Packagist](https://packagist.org/packages/ripaclub/zf2-sphinxsearch-tool)[ Docs](https://github.com/ripaclub/zf2-sphinxsearch-tool)[ RSS](/packages/ripaclub-zf2-sphinxsearch-tool/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (7)Versions (5)Used By (1)

[![Help message](help-img.png "Help message")](help-img.png)

**Sphinx Search Tool** is an utility that provides a set of tools to **create Sphinx Search configurations and data sources**.

[![Latest Stable Version](https://camo.githubusercontent.com/0d0f5e03f12dd387506c4339de88f04f19850356e48722597f17b7826b23e408/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72697061636c75622f7a66322d737068696e787365617263682d746f6f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ripaclub/zf2-sphinxsearch-tool) [![License](https://camo.githubusercontent.com/b7cd0a5fa416739f0d3873d2dd90095ec3814ee2a3c3f8cff4b6e9e23c3dd036/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72697061636c75622f7a66322d737068696e787365617263682d746f6f6c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/ripaclub/zf2-sphinxsearch-tool/blob/master/LICENSE)

Features
--------

[](#features)

- Console actions about Sphinx Search **configurations**

    - A **variable substitutions mechanism** (see [here](#configuration))
    - An automated way to **build** a Sphinx Search **configuration** from a ZF2 configuration (e.g. a PHP file returning a configuration array)
    - A set of already defined useful variables, particularly the UTF-8 **charset tables**

        - `charset_utf8_digits`, map to tokenize only digits
        - `charset_utf8_alphabet`, case-insensitive map for [ISO basic latin alphabet](http://en.wikipedia.org/wiki/ISO_basic_Latin_alphabet)
        - `charset_utf8_latin_extra`, table for special latin chars
        - `charset_utf8_a` to `charset_utf8_z` maps that normalize diacritics
        - `charset_utf8_default`, map that merge all the previous togheter
        - language based charse tables, e.g. `charset_utf8_it`, `charset_utf8_en`, `charset_utf8_de`, `charset_utf8_es`, `charset_utf8_zh`, `charset_utf8_ja`, ...
- Classes to generate Sphinx Search **data source files or streams**

    - Class to generate **XML** data for `xmlpipe2` (see [docs](http://sphinxsearch.com/docs/current.html#xmlpipe2))
    - Class to generate **TSV** data for `tsvpipe` (see [docs](http://sphinxsearch.com/docs/current.html#tsvpipe))
- Can be used from command line as a **standalone CLI tool** or can be installed as a **ZF2 module**

References
----------

[](#references)

- [Sphinx Search configuration options](http://sphinxsearch.com/docs/current.html#conf-reference)

Requirements
------------

[](#requirements)

- Zend Framework 2.0.0 or later
- PHP 5.4.0 or later
- Console access to the application being maintained (shell, command prompt)

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

[](#installation)

### Standalone installation using [composer](http://getcomposer.org)

[](#standalone-installation-using-composer)

1. Open console (command prompt)
2. `git clone https://github.com/ripaclub/zf2-sphinxsearch-tool.git`
3. `cd zf2-sphinxsearch-tool`
4. Run `composer install`

### Installation as ZF2 module using [composer](http://getcomposer.org)

[](#installation-as-zf2-module-using-composer)

1. Open console (command prompt)
2. Go to your application's directory
3. Add the following to your **composer.json**

```
{
    ...,
    "require": {
        "ripaclub/zf2-sphinxsearch-tool": "dev-develop"
    },
    "repositories": [
        {
        "type": "vcs",
        "url": "https://github.com/ripaclub/zf2-sphinxsearch-tool.git"
        }
    ]
}
```

4. Run a `composer update`

Usage
-----

[](#usage)

The entry point of the tool is the `sphinx-tool.php` file.

So executing it without commands, i.e. `php -f sphinx-tool.php`, the help message will be shown.

The usage of this tool is self-explanatory.

You can output (as array) to your console the Sphinx Search settings stored in the ZF2 configuration files (e.g. `module.config.php`) or in an external configuration file (e.g. `sphinx.conf.php`).

The Sphinx Search settings here specified will be merged with the default settings contained in ZF2 Sphinx Search Tool.

```
php -f sphinx-tool.php sphinx show config
php -f sphinx-tool.php sphinx show config --file=sphinx.conf.php
```

Also, you can directly write the configuration in the Sphinx Search format.

```
php -f sphinx-tool.php sphinx print config --output=config/sphinx.dev.conf
php -f sphinx-tool.php sphinx print config --input=sphinx.conf.php --output=config/sphinx.dev.conf
```

##### Note

[](#note)

If you use ZF2 Sphinx Search Tool as a module included into your application you can call its actions from your application entry point.

### Configuration

[](#configuration)

A Sphinx Search configuration can be defined via the `sphinxsearch` node element into you ZF2 configurations. The children of this node will be merged (i.e. added or substituted to) with defaults provided by ZF2 Sphinx Search Tool.

It can have this children:

- `variables`

    This node contains the variables that will be substituted into all your Sphinx Search configuration options. Some default variables are `log_path`, `lib_path`, `run_path`, and `idx_path` (respectively set to `/var/log/sphinx`, `/var/lib/sphinx`, `/var/run/sphinx`, and `/var/idx/sphinx`). You can define your variables (or override the defaults) and use them into your other settings wrapping them inside brackets.
- `searchd`

    Insert here your [search configuration options](http://sphinxsearch.com/docs/current.html#confgroup-searchd)
- `indexer`

    Insert here your [indexer configuration options](http://sphinxsearch.com/docs/current.html#confgroup-indexer)
- `common`

    Insert here your [common section configuration options](http://sphinxsearch.com/docs/current.html#confgroup-common)
- `indexes`

    This node contains the configurations of your indexes as an associative array which keys corresponds to index names. For each index you defined you have to specify its [options](http://sphinxsearch.com/docs/current.html#confgroup-index) via associative arrays (also multidimensional if needed)
- `sources`

    This node contains the configurations of you data source as an associative array which keys corresponds to source names. For each data source you defined you have to specifiy its [options](http://sphinxsearch.com/docs/current.html#confgroup-source) via associative arrays (also multidimensional if needed)

#### Example

[](#example)

An example of PHP array that defines a Sphinx Search configuration:

```
return [
    'sphinxsearch' => [
        'variables' => [
            'idx_path' => '/path/to/idx'
        ],
        'searchd' => [
            'listen' => '9306:mysql41',
            'log' => '{log_path}/searchd.log',
            'query_log' => '{log_path}/query.log',
            'pid_file' => '{run_path}/searchd.pid',
            'workers' => 'threads',
            'binlog_path' => '{lib_path}',
            'sphinxql_state' => '{run_path}/state.sql',
        ],
        'indexer' => [
            'mem_limit' => '512M',
            'write_buffer' => '16M',
        ],
        'indexes' => [
            'realtime' => [
                'type' => 'rt',
                'path' => '{idx_path}/realtime',
                'rt_field' => ['title', 'content'],
                'rt_attr_uint' => 'gid',
            ],
            'main' => [
                'source' => 'main',
                'path' => '{idx_path}/main',
            ],
            'delta : main' => [
                'source' => 'delta',
                'path' => '{idx_path}/delta',
            ]
        ],
        'sources' => [
            'main' => [
                'sql_query_pre' => ['SET NAMES utf8', 'REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents'],
                'sql_query' => 'SELECT id, title, body FROM documents WHERE id(SELECT max_doc_id FROM sph_counter WHERE counter_id=1)',
            ]
        ]
    ]
];
```

### Create data sources

[](#create-data-sources)

Suppose you have a result set (e.g. variable `$results`) obtained from a database (e.g. MongoDB) and you want to index it with Sphinx Search to serve searches through a plain index.

First of all we need to create a data source (e.g. an `xmlpipe2` source) that will stream our documents to the standard output (for this purpose we do not specify any URI for the writer).

```
use SphinxSearch\Tool\Source\Writer\XML2;
...
    $writer = new XML2();
    $writer->setFields(
        [
            ['name' => 'name', 'attr' => 'string'],
            ['name' => 'type'],
        ]
    );
    $writer->setAttributes(
        [
            ['name' => 'lat', 'type' => 'float'],
            ['name' => 'lng', 'type' => 'float'],
            ['name' => 'price', 'type' => 'int'],
        ]
    );
    echo $writer->beginOutput();
    $count = 1;
    foreach ($results as $result) {
        $document = [
            'id'                 => $count,
            'name'               => $result['name'],
            'lat'                => deg2rad(floatval($result['lat'])),
            'lng'                => deg2rad(floatval($result['lng'])),
            'price'              => (int) $result['price'],
        ];
        echo $writer->addDocument($document);
        $count++;
    }
    echo $writer->endOutput();
...
```

Suppose to wrap previous code in a controller console action (i.e. `sphinx xmlpipe2`), we can therefore use it as our `xmlpipe_command` to populate the Sphinx Search index.

The `sphinx.config.php` of our project is:

```
return [
    'sphinxsearch' => [
        'indexes' => [
            'my_idx' => [
                'type' => 'plain',
                'path' => '{idx_path}restaurant_it',
                'source' => 'my_source',
                'dict' => 'keywords',
                'charset_type' => 'utf-8',
                'charset_table' => '{charset_utf8_default}',
            ],
        ],
        'sources' => [
            'my_source' => [
                'type' => 'xmlpipe2',
                'xmlpipe_command' => '/usr/bin/php -f /path/to/project/public/index.php sphinx xmlpipe2'
            ]
        ]
    ]
];
```

We can now generate the `sphinx.conf`:

```
./vendor/bin/sphinx-tool.php sphinx print config --input=sphinx.config.php --output=sphinx.conf
```

Everything is now ready. We can call the indexer command (i.e. `indexer -c sphinx.conf --all --rotate`) and serve searches.

---

[![Analytics](https://camo.githubusercontent.com/01ca6dcfabf55637a99535e55c9a8718927905be6a7320814dd1d787a895bdf5/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d34393635373137362d332f7a66322d737068696e787365617263682d746f6f6c)](https://github.com/igrigorik/ga-beacon)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93% 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 ~113 days

Total

3

Last Release

4130d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/120051?v=4)[Leo Di Donato](/maintainers/leodido)[@leodido](https://github.com/leodido)

![](https://www.gravatar.com/avatar/376c46dedf9febc5ed5f99f8aed6269b93e2e7ea09b71e2d8f26faf078fd10ad?d=identicon)[leogr](/maintainers/leogr)

---

Top Contributors

[![leodido](https://avatars.githubusercontent.com/u/120051?v=4)](https://github.com/leodido "leodido (147 commits)")[![leogr](https://avatars.githubusercontent.com/u/3390997?v=4)](https://github.com/leogr "leogr (8 commits)")[![fntlnz](https://avatars.githubusercontent.com/u/3083633?v=4)](https://github.com/fntlnz "fntlnz (3 commits)")

---

Tags

searchutf-8configurationxmlconfigdatacharsettoolzf2tsvsphinxindexingsearch enginedata-sourcecharset map

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ripaclub-zf2-sphinxsearch-tool/health.svg)

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

###  Alternatives

[ripaclub/sphinxsearch

Sphinx Search library provides SphinxQL indexing and searching features

6232.2k3](/packages/ripaclub-sphinxsearch)[nilportugues/sphinx-search

Fully unit tested SphinxClient (SphinxAPI) for PHP5.3 and above to be used with SphinxSearch

18452.9k2](/packages/nilportugues-sphinx-search)[opensearchserver/opensearchserver

PHP library for OpenSearchServer: professionnal search engine, crawlers (web, file, database), REST APIs, .... This library uses OpenSearchServer's V2 API.

5267.5k](/packages/opensearchserver-opensearchserver)[javer/sphinx-bundle

Provides integration of Sphinx search engine with Symfony using SphinxQL

24185.4k](/packages/javer-sphinx-bundle)[algolia/laravel-scout-algolia-macros

A collection macros to extend Laravel Scout with more Algolia capabilities

3633.7k](/packages/algolia-laravel-scout-algolia-macros)[danack/configurator

Generates config files from PHP, JSON and Yaml data files.

159.9k](/packages/danack-configurator)

PHPackages © 2026

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