PHP code example of kvf77 / manticore-query-builder

1. Go to this page and download the library: Download kvf77/manticore-query-builder 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/ */

    

kvf77 / manticore-query-builder example snippets


use Kvf77\Manticore\Drivers\Pdo\Connection;
use Kvf77\Manticore\SphinxQL;

$conn = new Connection();
$conn->setParams(['host' => '127.0.0.1', 'port' => 9306]);

$result = (new SphinxQL($conn))
    ->select('id', 'title')
    ->from('articles')
    ->match('title', 'manticore')
    ->where('published', 1)
    ->orderBy('id', 'desc')
    ->limit(20)
    ->execute();

foreach ($result as $row) {
    // ...
}

$qb->select()->from('idx')
    ->where('a', 1)
    ->orWhere('b', 2)
    ->where(function (SphinxQL $q) {
        $q->where('c', 3)->orWhere('d', 4);
    });
// WHERE a = 1 OR b = 2 AND (c = 3 OR d = 4)

$qb->where('id', 'IN', [1, 2, 3]);          // id IN (1, 2, 3)
$qb->where('price', 'BETWEEN', [10, 100]);  // price BETWEEN 10 AND 100

$qb->select()->from('idx')->regex('title', '.*foo.*');
// WHERE REGEX(title, '.*foo.*')

(new SphinxQL($conn))->insert()->into('idx')->set(['id' => 1, 'name' => 'John'])->execute();
(new SphinxQL($conn))->replace()->into('idx')->set(['id' => 1, 'name' => 'John'])->execute();
(new SphinxQL($conn))->update('idx')->value('views', 5)->where('id', 1)->execute();
(new SphinxQL($conn))->delete()->from('idx')->where('id', 1)->execute();

use Kvf77\Manticore\Laravel\Facades\Manticore;

Manticore::insert('articles', ['id' => 1, 'title' => 'Hello']);
Manticore::replace('articles', ['id' => 1, 'title' => 'Hello again']);
Manticore::delete('articles', 1);

$rows = Manticore::select('id', 'title')
    ->from('articles')
    ->match('title', 'hello')
    ->execute();

$manticore = app(\Kvf77\Manticore\Laravel\Manticore::class);
$conn      = app(\Kvf77\Manticore\Drivers\ConnectionInterface::class);
bash
php artisan vendor:publish --tag=manticore-config