PHP code example of mnshankar / sphinxql

1. Go to this page and download the library: Download mnshankar/sphinxql 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/ */

    

mnshankar / sphinxql example snippets


    'providers' => array(
        'mnshankar\Sphinxql\SphinxqlServiceProvider',
    )

    'aliases' => array(
        'SphinxQL'         => 'mnshankar\Sphinxql\Facades\SphinxqlFacade',
    )

php artisan config:publish mnshankar/sphinxql

index rt_test
{
    type = rt   
    path = /var/lib/sphinxsearch/data/rt
    rt_field = title
    rt_field = content
    rt_attr_uint = gid
}
searchd
{
    # Configure the searchd listening port.
    listen = 9306:mysql41
    binlog_path = /var/lib/sphinxsearch/data
    pid_file = /var/www/sphinx-rt/app/storage/sphinx/searchd.pid

    # sudo searchd -c sphinx.conf - to start search daemon listening on above port   
    # mysql -P 9306 -h 127.0.0.1 - connect to sphinx server daemon
}        

Blog::created(function($model){
	$qins = SphinxQL::query()->insert()->into('rt_test');
	$qins->set(array('id'=>99, 'title'=>'My Title', 'content'=>'My Content', 'gid'=>444))->execute();
	//more realistically, it will look something like
	//$qins->set($model->toArray())->execute();
});

Blog::updated(function($model){
	$qrepl = SphinxQL::query()->replace()->into('rt_test');
	$qrepl->set(array('id'=>99, 'title'=>'My Title', 'content'=>'My Content', 'gid'=>444))->execute();
});

Blog::deleted(function($model){
	SphinxQL::query()->delete()->from('rt_test')->where('id',$model->id)->execute();
});

$q = SphinxQL::query()->select()->from('rt_test')->match('content', 'test');
	       ->execute();	       

dd($q->compile()->getCompiled());

SphinxQL::query()->meta();

$q = SphinxQL::raw('select * from rt_test');

$q = SphinxQL::query()->select()
			->from('rt_test')
			->match('content', 'test')
	       	->execute();
	       	
dd(SphinxQL::with($q)->get('Blog'));	       	

public function get($name=null, $key='id')