shopsys / postgres-search-bundle
Tools to use full-text search PostgreSQL in Doctrine.
Installs: 182 182
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 34
Type:symfony-bundle
Requires
- php: >=8.1
- doctrine/orm: >=2.2.3
- symfony/framework-bundle: >=2.1
This package is auto-updated.
Last update: 2024-11-30 01:56:26 UTC
README
Attention Users and Contributors:
This project is no longer actively maintained and developed.
PostgreSearchBundle
Symfony2 bundle with tools full-text search PostgreSQL in Doctrine 2.
Added type 'tsvector' to be used in the mapping.
Added functions 'to_tsquery', 'plainto_tsquery' and 'ts_rank' to be used in the DQL.
Step 1: Download PostgreSearchBundle using composer
Add PostgreSearchBundle in your composer.json:
{ "require": { "shopsys/postgres-search-bundle": "0.1" } }
Now tell composer to download the bundle by running the command:
$ php composer.phar update shopsys/postgres-search-bundle
Step 2: Enable the bundle
Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Intaro\PostgresSearchBundle\IntaroPostgresSearchBundle(), ); }
Step 3: Mapping example
/** * @var string * * @ORM\Column(name="search_fts", type="tsvector", options={"customSchemaOptions": {"searchFields":{"name", "genre"}}}, nullable=true) */ protected $searchFts;
Step 4: Use in DQL
$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();
Result example:
Array ( [0] => Array ( [id] => 2 [rank] => 0.0607927 ) [1] => Array ( [id] => 3 [rank] => 0.0303964 ) )