PHP code example of fullpipe / sphinxsearch-bundle

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

    

fullpipe / sphinxsearch-bundle example snippets

 php
$indexesToSearch = array('Items');
$sphinxSearch = $this->get('search.sphinxsearch.search');
$searchResults = $sphinxSearch->search('search query', $indexesToSearch);

    array(10) {
        ["error"]=> string(0) ""
        ["warning"]=> string(0) ""
        ["status"]=> int(0)
        ...

        ["matches"]=> array(28) {
            [123]=> array(2) {
                ...
                ["weight"]=> string(1) "9"

                ["entity"]=> object(Acme\DemoBundle\Entity\Item) //here is my Item

                ["attrs"]=> array(1) {
                    ["name"]=> string(33) "Лаврова Екатерина"
                }
                ...
            }
        }

        ...
 php
$indexesToSearch = array('Items');
$options = array(
  'result_offset' => 0,
  'result_limit' => 25,
  'field_weights' => array(
    'Name' => 2,
    'SKU' => 3,
  ),
);
$sphinxSearch = $this->get('search.sphinxsearch.search');
$sphinxSearch->setMatchMode(SPH_MATCH_EXTENDED2);
$sphinxSearch->setFilter('disabled', array(1), true);
$searchResults = $sphinxSearch->search('search query', $indexesToSearch, $options);
 php
use use Pagerfanta\Pagerfanta;

...

$adapter = $this->get('search.sphinxsearch.pagerfanta.adapter');

$indexesToSearch = array('Items');
$options = array(
  'field_weights' => array(
    'Name' => 2,
    'SKU' => 3,
  ),
);

$adapter->setSearchParams('search query', $indexesToSearch, $options);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(28);
$pagerfanta->setCurrentPage($request->get('page', 1));