PHP code example of diezeel / laravel-sphinx

1. Go to this page and download the library: Download diezeel/laravel-sphinx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diezeel / laravel-sphinx example snippets


DieZeeL\Database\SphinxConnection\SphinxServiceProvider::class,

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

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

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

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();

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

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

    $sq->insert([
        'id' => 1,
        'tags' => [1, 2, 3]
    ]);
    // Output: INSERT INTO rt (id, tags) VALUES(1, (1, 2, 3))
   

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

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

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

    $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) 
    

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