PHP code example of rikiless / sphinx-search

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

    

rikiless / sphinx-search example snippets


class Presenter ...
{

	/** @var Rikiless\Sphinx\Search @inject */
	public $fulltextSearch;

}

$fulltext = new Rikiless\Sphinx\Search([
    'host' => 'localhost',
    'port' => 9312
]);

try {
 	/** @var Rikiless\Sphinx\Data $results */
    $results = $fulltext->query('search something');
	var_dump($results->getMatchesList());
	
} catch (Rikiless\Sphinx\Exception $e) {
    print $e->getMessage();
}

$search = 'search something';

$this->fulltextSearch->setIndex('myindex');
$this->fulltextSearch->setLogComment(sprintf('Fulltext query on %s', $this->domain));
$this->fulltextSearch->setFieldWeights([
    'name' => 10,
	'content' => 5,
	'subject_name' => 3,
	'city' => 2,
	'contact_person' => 2
]);

$this->fulltextSearch->resetFilters();
$this->fulltextSearch->setFilterRange('position', 0, 19999999);
$this->fulltextSearch->addQuery($search);

$this->fulltextSearch->resetFilters();
$this->fulltextSearch->setFilterRange('position', 20000000, 29999999);
$this->fulltextSearch->addQuery($search);

try {
    $results = $this->fulltextSearch->runQueries();
} catch (Rikiless\Sphinx\Exception $e) {
    print $e->getMessage();
}

foreach ($results as $row) {
	/** @var Rikiless\Sphinx\Data $row */
	var_dump($row->getMatches());
}