PHPackages                             diezeel/laravel-sphinx - 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. diezeel/laravel-sphinx

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

diezeel/laravel-sphinx
======================

A Laravel query builder for SphinxQL

v0.5.0(6y ago)07.4kMITPHPPHP &gt;=5.5.9

Since Oct 7Pushed 6y agoCompare

[ Source](https://github.com/DieZeeL/laravel-sphinx)[ Packagist](https://packagist.org/packages/diezeel/laravel-sphinx)[ RSS](/packages/diezeel-laravel-sphinx/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (13)Used By (0)

Sphinx Query Builder for Laravel
================================

[](#sphinx-query-builder-for-laravel)

[![Build Status](https://camo.githubusercontent.com/23b65498f7a54beccf30685d203cdb492a7719084e170e3b4dfe1d78dceefd0c/68747470733a2f2f7472617669732d63692e6f72672f666f6269617068702f6c61726176656c2d737068696e782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fobiaphp/laravel-sphinx)[![Latest Stable Version](https://camo.githubusercontent.com/02f9faf375da580ab0233c1e359007531dfe0e6d45816259b4748a192ef3797b/68747470733a2f2f706f7365722e707567782e6f72672f666f6269612f6c61726176656c2d737068696e782f762f737461626c65)](https://packagist.org/packages/fobia/laravel-sphinx)

Laravel-Sphinx Database connector, providing an expressive query builder, Eloquent, ActiveRecord style ORM

- [Config](#config)
- [Usage](#usage)
- [Query Builder](#query-builder)
    - [MATCH](#match)
    - [WITHIN GROUP, ORDER, OPTION](#within-group-order-option)
- [Api SphinxConnection](#api-sphinxconnection)
- [Resources](#resources)

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

[](#installation)

laravel-sphinx can be installed with [Composer](http://getcomposer.org)by adding it as a dependency to your project's composer.json file.

```
{
    "require": {
        "diezeel/laravel-sphinx": "*"
    }
}
```

Please refer to [Composer's documentation](https://github.com/composer/composer/blob/master/doc/00-intro.md#introduction)for more detailed installation and usage instructions.

Config
------

[](#config)

After updating composer, add the ServiceProvider to the providers array in config/app.php

```
DieZeeL\Database\SphinxConnection\SphinxServiceProvider::class,
```

Finally you can just add `Sphinx Connection` to the database array in config/database.php

```
    'sphinx' => [
        'driver'   => 'sphinx',
        'host'     => env('SPHINX_HOST', env('DB_HOST','127.0.0.1')),
        'port' => 9306,
    ],
```

Usage
-----

[](#usage)

Get a connection and build queries

```
    $db = \DB::connection('sphinx');
```

**Using The Query Builder**

```
$users = $db->table('rt')->where('votes', '>', 100)->get();
```

**Using The Eloquent ORM**

```
class Product extends \DieZeeL\Database\SphinxConnection\Eloquent\Model {}

$product = Product::find(1);

$products = Product::where('votes', '>', 1)->get();
$products = Product::match('name', 'match text')->get();
```

**Attribute Casting**For the results of the column `attr_multi` can choose the format, which is converted to an array.

The values of `'(1, 2, 3)'` for column type `attr_multi` converted to an array `[1, 2, 3]`

```
class Product extends \DieZeeL\Database\SphinxConnection\Eloquent\Model
{
    protected $casts = [
        'tags' => 'mva',
    ];
}
```

### Query Builder

[](#query-builder)

```
    $sq = $db->table('rt');
```

For the build a query, using strong typing of values (how in SphinxQl).

> Notice: **`id = 1`** and **`id = '1'`** not the same

- **integer** It is used to type integer `attr_uint`
- **float** It is used to type float `attr_float`
- **bool** (integer) It is used to type bool `attr_bool`, will be converted to integer (0 or 1)
- **array** (MVA) It is used to type MVA `attr_multi`

    ```
    $sq->insert([
        'id' => 1,
        'tags' => [1, 2, 3]
    ]);
    // Output: INSERT INTO rt (id, tags) VALUES(1, (1, 2, 3))
    ```
- **string** - string values, escaped when requested

    ```
    $sq->insert([
        'id' => 1,
        'name' => "name 'text'"
    ]);
    // Output: INSERT INTO rt (id, name) VALUES(1, 'name \'text\'')
    ```

#### MATCH

[](#match)

- **$sq-&gt;match($column, $value, $half = false)**

    Search in full-text fields. Can be used multiple times in the same query. Column can be an array. Value can be an Expression to bypass escaping (and use your own custom solution).

    ```
