PHP code example of shopsys / postgres-search-bundle

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

    

shopsys / postgres-search-bundle example snippets


/**
 * @var string
 *
 * @ORM\Column(name="search_fts", type="tsvector", options={"customSchemaOptions": {"searchFields":{"name", "genre"}}}, nullable=true)
 */
protected $searchFts;

$searchQuery = 'family | history';
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
    'SELECT b.id, sum(TSRANK(b.searchFts, :searchQuery)) as rank
        FROM DemoSearchBundle:Books b
        WHERE TSQUERY( b.searchFts, :searchQuery, \'simple\' ) = true
        GROUP BY b.id
        ORDER BY rank DESC')
    ->setParameter('searchQuery', $searchQuery)
;
$result = $query->getArrayResult();
 bash
$ php composer.phar update shopsys/postgres-search-bundle
 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Intaro\PostgresSearchBundle\IntaroPostgresSearchBundle(),
    );
}