slkxmail/postgres-search-bundle
Composer 安装命令:
composer require slkxmail/postgres-search-bundle
包简介
Tools to use full-text search PostgreSQL in Doctrine.
README 文档
README
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": { "intaro/postgres-search-bundle": "dev-master" } }
Now tell composer to download the bundle by running the command:
$ php composer.phar update intaro/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 ) )
统计信息
- 总下载量: 601
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-18