jrk/levenshtein-bundle
最新稳定版本:v1.1.1
Composer 安装命令:
composer require jrk/levenshtein-bundle
包简介
Levenshtein function bundle for symfony2 and doctrine
README 文档
README
Setup
JrkLevenshteinBundle requires Symfony and Doctrine
- Using composer
Add jrk/levenshtein-bundle as a dependency in your project's composer.json file:
{
"require": {
"jrk/levenshtein-bundle": "dev-master"
}
}
Update composer
php composer update
or
php composer.phar update
- Add JrkLevenshteinBundle to your application kernel
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Jrk\LevenshteinBundle\JrkLevenshteinBundle(), ); }
- Yml configuration
# app/config/config.yml doctrine: orm: entity_managers: default: dql: numeric_functions: levenshtein: Jrk\LevenshteinBundle\ORM\Doctrine\DQL\LevenshteinFunction levenshtein_ratio: Jrk\LevenshteinBundle\ORM\Doctrine\DQL\LevenshteinRatioFunction
or if you're using shortened configuration instead of full configuration
#app/config/config.yml doctrine: orm: # if you have these lines auto_generate_proxy_classes: '%kernel.debug%' naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true # you've to directly put the dql lines, see below dql: numeric_functions: levenshtein: Jrk\LevenshteinBundle\ORM\Doctrine\DQL\LevenshteinFunction levenshtein_ratio: Jrk\LevenshteinBundle\ORM\Doctrine\DQL\LevenshteinRatioFunction
- Console usage
Install functions
php app/console jrk:levenshtein:install
That console line will install 2 functions in your database. You can inspect these functions in your mysql database by typing in a phpmyadmin sql prompt or in your favorite mysql client
SHOW FUNCTION STATUS;
Usage
- Using QueryBuilder
<?php public function getUserByFirstname($tolerance = 3) { $queryBuilder = $this->_em->createQueryBuilder() ->select('user') ->from('FooBundle:User','user') ->where('LEVENSHTEIN(user.firstname,:searchString) <= :tolerance') ->setParameter('searchString',$searchString) ->setParameter('tolerance',$tolerance) ; return $queryBuilder->getQuery()->getResult(); } ?>
- Using DQL
<?php public function getUserByFirstname($tolerance = 3) { $dqlString = ' SELECT user FROM FooBundle:User user WHERE LEVENSHTEIN(user.firstname,:searchString) <= :tolerance '; $query = $this->_em->createQuery($dqlString) ->setParameter('searchString',$searchString) ->setParameter('tolerance',$tolerance) ; return $query->getResult(); } ?>
统计信息
- 总下载量: 47.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-30