PHPackages                             euclid1990/php-sphinx-search - 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. euclid1990/php-sphinx-search

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

euclid1990/php-sphinx-search
============================

PHP Sphinx search tool.

1.0.1(10y ago)93.0k5MITPHPPHP &gt;=5.4

Since Mar 26Pushed 9y ago1 watchersCompare

[ Source](https://github.com/euclid1990/php-sphinx-search)[ Packagist](https://packagist.org/packages/euclid1990/php-sphinx-search)[ RSS](/packages/euclid1990-php-sphinx-search/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (3)Used By (0)

PHP Sphinx Search
=================

[](#php-sphinx-search)

[![Latest Stable Version](https://camo.githubusercontent.com/bb1ec35e52696845633b0952c3d0ec9cf3c97509376d2cc677042e38e7a98ee5/68747470733a2f2f706f7365722e707567782e6f72672f6575636c6964313939302f7068702d737068696e782d7365617263682f76657273696f6e)](https://packagist.org/packages/euclid1990/php-sphinx-search)[![Total Downloads](https://camo.githubusercontent.com/b447d89ee76cd3a97beea9203f18ecda6960512d3af47e1a478fd414f57ed4fe/68747470733a2f2f706f7365722e707567782e6f72672f6575636c6964313939302f7068702d737068696e782d7365617263682f646f776e6c6f616473)](https://packagist.org/packages/euclid1990/php-sphinx-search)[![License](https://camo.githubusercontent.com/ab0132e3999815a2419a3385dfaa526351773aec7bc5020f7ce1df0f83fde609/68747470733a2f2f706f7365722e707567782e6f72672f6575636c6964313939302f7068702d737068696e782d7365617263682f6c6963656e7365)](https://packagist.org/packages/euclid1990/php-sphinx-search)

PHP Sphinx search tool (An external solution for database full-text search). Support Composer &amp; Laravel Framework.

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

[](#installation)

[PHP](https://php.net) 5.4 is required.

The PHP Sphinx Search Service Provider can be installed via [Composer](http://getcomposer.org) by requiring the `euclid1990/php-sphinx-search` package in your project's `composer.json`.

```
{
    "require": {
        "euclid1990/php-sphinx-search": "~1.0"
    },
    "minimum-stability": "stable"
}
```

or

Require this package with composer:

```
composer require euclid1990/php-sphinx-search

```

Update your packages with `composer update` or install with `composer install`.

Setup
-----

[](#setup)

#### 1. Commmon PHP

[](#1-commmon-php)

Add boostrap autoload file:

```
require_once __DIR__ . '/../vendor/autoload.php';

use euclid1990\PhpSphinxSearch\SphinxSearch;
```

#### 2. For Laravel

[](#2-for-laravel)

- To use the Sphinx Search Service, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

Find the `providers` key in `config/app.php` and register the Sphinx Search Service Provider.

```
    'providers' => [
        // ...
        'euclid1990\PhpSphinxSearch\Providers\SphinxSearchServiceProvider',
    ]
```

for Laravel 5.1+

```
    'providers' => [
        // ...
        euclid1990\PhpSphinxSearch\Providers\SphinxSearchServiceProvider::class,
    ]
```

Find the `aliases` key in `config/app.php`.

```
    'aliases' => [
        // ...
        'SphinxSearch' => 'euclid1990\PhpSphinxSearch\Facades\SphinxSearch',
    ]
```

for Laravel 5.1+

```
    'aliases' => [
        // ...
        'SphinxSearch' => euclid1990\PhpSphinxSearch\Facades\SphinxSearch::class,
    ]
```

- If you need to override the default configuration options (server/port), please use the config publish command

```
php artisan config:publish euclid1990/php-sphinx-search

```

- For Laravel 5.4 config:publish does not work. Use the below command instead.

```
php artisan vendor:publish

```

Usage
-----

[](#usage)

#### 1. Common PHP:

[](#1-common-php)

Please refer to [demo/run.php](https://github.com/euclid1990/php-sphinx-search/blob/master/demo/run.php) or you can execute this command line:

```
# php demo/run.php

```

```
require_once __DIR__ . '/../vendor/autoload.php';

use euclid1990\PhpSphinxSearch\SphinxSearch;

$configArr = require __DIR__.'/../config/sphinx_search.php';
$config = ['sphinx_search' => $configArr];
$sphinxSearch = new SphinxSearch(new Illuminate\Config\Repository($config));

$keyword = 'source code';
$matchs = ['title', 'content'];
$table = 'posts';
$columns = ['id', 'title', 'content'];
$offset = 0;
$limit = 10;
$result = $sphinxSearch->search($keyword, $matchs, $table, $columns, $offset, $limit);
echo "Search results for keyword: [$keyword].\n";
print_r($result->toArray());
```

[Click to view Result](https://raw.githubusercontent.com/euclid1990/php-sphinx-search/master/demo/images/common.png)

#### 2. For Laravel

[](#2-for-laravel-1)

```
$keywordEnglish = 'source code';
$keywordVietnamse = 'web nhanh mạnh';
$keywordJapanese = '私は です か';

$matchs = ['title', 'content'];
$table = 'posts';
$columns = ['id', 'user_id', 'title', 'content', 'created_at'];

// Facade class method
$resultEnglish = \SphinxSearch::search($keywordEnglish, $matchs, $table);
echo "Search results for English keyword: [$keywordEnglish].\n";
dump($resultEnglish->toArray());

$resultVietnamse = \SphinxSearch::search($keywordVietnamse, $matchs, $table);
echo "Search results for Vietnamese keyword: [$keywordVietnamse].\n";
dump($resultVietnamse->toArray());

$resultJapanese = \SphinxSearch::search($keywordJapanese, $matchs, $table);
echo "Search results for Japanese keyword: [$keywordJapanese].\n";
dump($resultJapanese->toArray());

// Helper
sphinx_search($keyword, $matchs, $table, $columns);

// Raw Query
$query = "SELECT id FROM posts WHERE MATCH('(@(title,content) source code)') LIMIT 1, 2";
sphinx_raw($query);

// Get sphinxQL
$sphinxQL = sphinx_ql();
$sphinxQL->select()->from($table)->execute();

// Get sphinxApi
$keyword = 'the source';
$tables = 'posts'
$resultApi = sphinx_api()->setMatchMode(SPH_MATCH_ANY)
                ->setFilter('category', [3])
                    ->query($keyword, $table);
```

[Click to view Result](https://raw.githubusercontent.com/euclid1990/php-sphinx-search/master/demo/images/preview.png)

Reference
---------

[](#reference)

#### Document

[](#document)

[Packagist](https://packagist.org/packages/euclid1990/php-sphinx-search)

[Sphinx Search Document](http://sphinxsearch.com/docs/)

[Sphinx Charset Table CJKV](http://sphinxsearch.com/wiki/doku.php?id=charset_tables)

[How To Install and Configure Sphinx on Ubuntu 14.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-sphinx-on-ubuntu-14-04)

#### Database

[](#database)

###### Just for testing purposes

[](#just-for-testing-purposes)

```
mysql -u{username} -p{password} {database}
