2017 © Pedro Peláez
 

project laravel-sphinx

A Laravel query builder for SphinxQL

image

fobia/laravel-sphinx

A Laravel query builder for SphinxQL

  • Monday, October 23, 2017
  • by fobia
  • Repository
  • 3 Watchers
  • 16 Stars
  • 5,458 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 8 Versions
  • 46 % Grown

The README.md

Sphinx Query Builder for Laravel

Build Status Latest Stable Version, (*1)

Laravel-Sphinx Database connector, providing an expressive query builder, Eloquent, ActiveRecord style ORM, (*2)

Installation

laravel-sphinx can be installed with Composer by adding it as a dependency to your project's composer.json file., (*3)

{
    "require": {
        "fobia/laravel-sphinx": "*"
    }
}

Please refer to Composer's documentation for more detailed installation and usage instructions., (*4)

Config

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

Fobia\Database\SphinxConnection\SphinxServiceProvider::class,

Finally you can just add Sphinx Connection to the database array in config/database.php, (*6)

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

Usage

Get a connection and build queries, (*7)

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

Using The Query Builder, (*8)

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

Using The Eloquent ORM, (*9)

class Product extends \Fobia\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., (*10)

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

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

Query Builder

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

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

Notice: id = 1 and id = '1' not the same, (*13)

  • integer It is used to type integer attr_uint, (*14)

  • float It is used to type float attr_float, (*15)

  • __bool__ (integer) It is used to type bool attr_bool, will be converted to integer (0 or 1), (*16)

  • __array__ (MVA) It is used to type MVA attr_multi, (*17)

    $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, (*18)

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

MATCH

  • $sq->match($column, $value, $half = false), (*19)

    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)., (*20)

    <?php
    $sq->match('title', 'Otoshimono')
        ->match('character', 'Nymph')
        ->match(array('hates', 'despises'), 'Oregano');
    
    $sq->match(function(\Foolz\SphinxQL\Match $m) {
          $m->not('text');
    });
    

    For a function match used library SphinxQL::match, (*21)

WITHIN GROUP, ORDER, OPTION

  • $sq->withinGroupOrderBy($column, $direction = 'ASC'), (*22)

    WITHIN GROUP ORDER BY $column [$direction], (*23)

    Direction can be omitted with null, or be ASC or DESC case insensitive., (*24)

  • $sq->orderBy($column, $direction = null), (*25)

    ORDER BY $column [$direction], (*26)

    Direction can be omitted with null, or be ASC or DESC case insensitive., (*27)

  • $sq->option($name, $value), (*28)

    OPTION $name = $value, (*29)

    Set a SphinxQL option such as max_matches or reverse_scan for the query., (*30)

whereMulti

  • $sq->whereMulti($column, $operator, $values), (*31)

    All parameters converted to a flat array, (*32)

    $sq->whereMulti('id', '=', [1, 2, 3, [4, 5]]);
    // Output: WHERE id = 1 and id = 2 and id = 3 and id = 4 and id = 5
    

    For the in and not in is different, (*33)

    $sq->whereMulti('id', 'in', [1, 2, 3]);
    // Output: WHERE id in (1) and id in (2) and id in (3) 
    
    $sq->whereMulti('id', 'in', [1, [20, 21], [30, 31]]);
    // Output: WHERE id in (1) and id in (20, 21) and id in (30, 31) 
    
    // Equivalently
    $sq->whereMulti('id', 'in', 1, [20, 21], [30, 31]);
    // Output: WHERE id in (1) and id in (20, 21) and id in (30, 31) 
    

Replace

  • $sq->replace($values), (*34)

    $sq->replace([
        'id' => 1,
        'name' => 'text name'
    ]);
    

API SphinxConnection

Resources

The Versions

23/10 2017

dev-master

9999999-dev

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

23/10 2017

v0.2.4

0.2.4.0

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

11/05 2017

v0.2.3

0.2.3.0

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

03/05 2017

dev-develop

dev-develop

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

13/10 2016

v0.2.2

0.2.2.0

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

09/10 2016

v0.2.1

0.2.1.0

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

08/10 2016

v0.2.0

0.2.0.0

A Laravel query builder for SphinxQL

  Sources   Download

MIT

The Requires

 

The Development Requires

database laravel sql query builder sphinx sphinxql sphinx eloquent

07/10 2016

v0.1

0.1.0.0

The Laravel Framework Sphinx connection.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel sphinx sphinx eloquent