PHP code example of foolz / sphinxql-query-builder
1. Go to this page and download the library: Download foolz/sphinxql-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/ */
foolz / sphinxql-query-builder example snippets
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Drivers\Mysqli\Connection;
// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setParams(array('host' => 'domain.tld', 'port' => 9306));
$query = (new SphinxQL($conn))->select('column_one', 'colume_two')
->from('index_ancient', 'index_main', 'index_delta')
->match('comment', 'my opinion is superior to yours')
->where('banned', '=', 1);
$result = $query->execute();
// WHERE `column` = 'value'
$sq->where('column', 'value');
// WHERE `column` = 'value'
$sq->where('column', '=', 'value');
// WHERE `column` >= 'value'
$sq->where('column', '>=', 'value');
// WHERE `column` IN ('value1', 'value2', 'value3')
$sq->where('column', 'IN', array('value1', 'value2', 'value3'));
// WHERE `column` NOT IN ('value1', 'value2', 'value3')
$sq->where('column', 'NOT IN', array('value1', 'value2', 'value3'));
// WHERE `column` BETWEEN 'value1' AND 'value2'
// WHERE `example` BETWEEN 10 AND 100
$sq->where('column', 'BETWEEN', array('value1', 'value2'));
use Foolz\SphinxQL\SphinxQL;
try
{
$result = (new SphinxQL($conn))
->select()
->from('rt')
->match('title', 'Sora no || Otoshimono', true)
->match('title', SphinxQL::expr('"Otoshimono"/3'))
->match('loves', SphinxQL::expr(custom_escaping_fn('(you | me)')));
->execute();
}
catch (\Foolz\SphinxQL\DatabaseException $e)
{
// an error is thrown because two `|` one after the other aren't allowed
}
use Foolz\SphinxQL\SphinxQL;
$result = (new SphinxQL($this->conn))
->select()
->from('rt')
->match('title', 'sora')
->enqueue((new SphinxQL($this->conn))->query('SHOW META')) // this returns the object with SHOW META query
->enqueue() // this returns a new object
->select()
->from('rt')
->match('content', 'nymph')
->executeBatch();
use Foolz\SphinxQL\SphinxQL;
$result = (new SphinxQL($this->conn))
->select()
->from('rt')
->where('gid', 9003)
->enqueue((new Helper($this->conn))->showMeta()) // this returns the object with SHOW META query prepared
->enqueue() // this returns a new object
->select()
->from('rt')
->where('gid', 201)
->executeBatch();
use Foolz\SphinxQL\Percolate;
$query = (new Percolate($conn))
->insert('full text query terms',false)
->into('pq')
->tags(['tag1','tag2'])
->filter('price>3')
->execute();
use Foolz\SphinxQL\Percolate;
$query = (new Percolate($conn))
->callPQ()
->from('pq')
->documents(['multiple documents', 'go this way'])
->options([
Percolate::OPTION_VERBOSE => 1,
Percolate::OPTION_DOCS_JSON => 1
])
->execute();
// Register connection:
use Foolz\SphinxQL\Drivers\ConnectionInterface;
use Foolz\SphinxQL\Drivers\Mysqli\Connection;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(ConnectionInterface::class, function ($app) {
$conn = new Connection();
$conn->setParams(['host' => 'domain.tld', 'port' => 9306]);
return $conn;
});
}
}
// In another file:
use Facades\Foolz\SphinxQL\SphinxQL;
$result = SphinxQL::select('column_one', 'colume_two')
->from('index_ancient', 'index_main', 'index_delta')
->match('comment', 'my opinion is superior to yours')
->where('banned', '=', 1)
->execute();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.