PHP code example of gemorroj / sphinx-bundle

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

    

gemorroj / sphinx-bundle example snippets



$client = $this->get('highco.sphinx.client');

$bridge = $this->get('highco.sphinx.pager.white_october.doctrine_orm');
// $bridge->setEntityManagerByName('my_custom_em');
// $bridge->setEntityManager($em);
$bridge->setRepositoryClass('HighcoUserBundle:User');
$bridge->setPkColumn('id');
$bridge->setSphinxResults($client->Query('Stéphane'));

$pager = $bridge->getPager();


$itemsPerPage = 50;
$page = 1;

$client = $this->get('highco.sphinx.client');
$client->SetLimits( ($page -1) * $itemsPerPage, $itemsPerPage);

$bridge = $this->get('highco.sphinx.pager.white_october.doctrine_orm');
$bridge->setRepositoryClass('HighcoUserBundle:User');
$bridge->setPkColumn('id');
$bridge->setSphinxResults($client->Query('Stéphane'));

$pager = $bridge->getPager();
$pager->setMaxPerPage($itemsPerPage);
$pager->setCurrentPage($page);


$itemsPerPage = 50;
$page = 1;

$client = $this->get('highco.sphinx.client');
$client->SetLimits( ($page -1) * $itemsPerPage, $itemsPerPage);

$bridge = $this->get('highco.sphinx.pager.white_october.doctrine_orm');
$bridge->setRepositoryClass('HighcoUserBundle:User');
$bridge->setPkColumn('id');

$client->AddQuery('Stéphane', 'address_book');
$client->AddQuery('Nikola', 'address_book');
$bridge->setSphinxResults($client->RunQueries(), true);

$pager = $bridge->getPager();
$pager->setMaxPerPage($itemsPerPage);
$pager->setCurrentPage($page);


$itemsPerPage = 50;
$page = 1;

$client = $this->get('highco.sphinx.client');
$client->SetLimits( ($page -1) * $itemsPerPage, $itemsPerPage);

$bridge = $this->get('highco.sphinx.pager.white_october.doctrine_orm');

/**
 * Make sure you have this column defined as attribute in Sphinx (i.e: sql_attr_string = type).
 * Sphinx prior version 1.10 does not have support for sql_attr_string, but you can use sql_attr_uint
 * and have your discriminators defined as constants in PHP.
 */
$bridge->setDiscriminatorColumn('type');

$bridge->setDiscriminatorRepositories(array(
    'article'       => array(
        'class' => 'BlogBundle:Article',
        'em'    => 'default',
    ),
    'category'      => array(
        'class' => 'BlogBundle:Category',
        'em'    => 'default',
    ),
    'note'         => array(
        'class' => 'NotesBundle:Message',
        'em'    => 'notes'
    ),
));

$bridge->setPkColumn('id');
$bridge->setSphinxResults($client->Query('Stéphane'));

$pager = $bridge->getPager();
$pager->setMaxPerPage($itemsPerPage);
$pager->setCurrentPage($page);