PHP code example of rosh1ck / sphinxsearch-bundle

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

    

rosh1ck / sphinxsearch-bundle example snippets


// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    $searchd->setLimits(0, 100);
    return $sphinxSearch->search($request->query->get('q', ''), array('IndexName'));
}
bash
$ php composer.phar update iakumai/sphinxsearch-bundle
 php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IAkumaI\SphinxsearchBundle\SphinxsearchBundle()
    );
}
 twig
<div class="text-block">
    {{ content|sphinx_highlight('IndexName', 'query word', {limit:100}) }}
</div>
 php
// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    return $sphinxSearch->search($request->query->get('q', ''), array('IndexName'));
}
 php
// In a controller
public function searchAction(Request $request)
{
    $searchd = $this->get('iakumai.sphinxsearch.search');
    $results_one = $sphinxSearch->searchEx($request->query->get('q', ''), 'IndexName');
    // or for multiple indexes (index_name attribute must exists)
    $results_two = $sphinxSearch->searchEx($request->query->get('q', ''), array('IndexName', 'SeconIndexName'));
}

array(10) {
  .....
  ["matches"]=>
  array(20) {
    [22]=>
    array(3) {
      ["weight"]=>
      string(1) "2"
      ["attrs"]=>
      array(0) {
      }
      ["entity"]=> ... // Here is your Bundle:Entity
    }
    .........

array(10) {
  .....
  ["matches"]=>
  array(20) {
    [22]=>
    array(3) {
      ["weight"]=>
      string(1) "2"
      ["attrs"]=>
      array(0) {
        ["index_name"]=>
        string(9) "IndexName"
      }
      ["entity"]=> ... // Here is your Bundle:Entity
    }
    .........
 php
/** @var $sphinx \IAkumaI\SphinxsearchBundle\Search\Sphinxsearch */
$sphinx = $this->get('iakumai.sphinxsearch.search');

/** @var $sphinxDoctrineBridge \IAkumaI\SphinxsearchBundle\Doctrine\Bridge */
$sphinxDoctrineBridge = $this->get('iakumai.sphinxsearch.doctrine.bridge');
$sphinx->setBridge($sphinxDoctrineBridge); //IMPORTANT! Set doctrine bridge.

$query = 'search query';
$entityIndexType = 'Books';

$adapter = new \IAkumaI\SphinxsearchBundle\Pagerfanta\Adapter\SphinxSearchAdapter($sphinx, $query, $entityIndexType, [
    'max_results' => 1000000,
]);
$pager = new Pagerfanta($adapter);
// Use pagerfanta as always
...