olegstepura/doctrine-multicolumn-search
Composer 安装命令:
composer require olegstepura/doctrine-multicolumn-search
包简介
Simply search multiple Doctrine ORM entities for a user query
README 文档
README
Simply search multiple entities for a user query.
Description
This is a query builder for Doctrine ORM designed to create a query for use with Pagerfanta. The created query searches any number of columns for a given query which is exploded into words and queried the way that all words must be included in the result row. Sql substitute character (%) may be included. It is written on PHP and intended to be used with Doctrine Doctrine ORM.
Description, again ;)
The search queries are not matched against one single column in database (as usual), but against several of them. So when you type 2 words searching for user in user database not only user name is searched, but also user email, second name and maybe description can be inspected to match the searched words. What columns to match is up to you and is configurable.
Lets assume you have a database table with all the users of your system.
+----+-------------+--------------+-----------------------+
| id | name | last_name | email |
+----+-------------+--------------+-----------------------+
| 1 | Leonardo | DiCaprio | strange@mailhost.com |
| 2 | John | Doe | john.doe@leonardo.ru |
| 3 | Bill | Gates | bill@gates.it |
| 4 | Will | Leonardo | will@leo.com |
| 5 | Leonardo123 | De Niro | leo@deniro.de |
+----+-------------+--------------+-----------------------+
Searching for "leonardo" will produce records 1, 2, 4 and 5. Searching for "leo com" will produce records 1, 2, 4 and 5. Searching for "bill com" will produce records 1, 3 and 4.
Usage example
Properties in given class are inspected with annotation reader for the ones
marked with \Ost\Doctrine\MultiColumnSearch\Searchable annotation.
Here is an example of entity (it can be found in tests folder):
/**
* User class.
* @ORM\Entity
* @ORM\Table(name="user")
* @author Oleg Stepura <oleg.stepura [at] gmail.com>
* @version 1.0
*/
class User
{
/**
* @ORM\Column(name="id")
* @ORM\Id
* @ORM\GeneratedValue
* @var int $id
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=64)
* @Searchable
* @var string $name
*/
private $name = '';
/**
* @ORM\Column(name="email", type="string", length=255)
* @Searchable
* @var string $email
*/
private $email = '';
/**
* @ORM\Column(name="password", type="string", length=40)
* @var string $password
*/
private $password = '';
}
And here is usage example.
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Doctrine\Common\Annotations\Reader;
$reader = new IndexedReader(new AnnotationReader());
$qb = new QueryBuilder($entityManager, $reader, __NAMESPACE__ . '\\User');
$pagerfanta = new Pagerfanta($qb->getPagerfantaAdapter('my query'));
// use Pagerfanta the usual way
$currentPageResults = $pagerfanta->getCurrentPageResults();
Configured with Symfony Dependency Injection even easier:
$container
->get('ost.doctrine.multicolumn_search.builder_factory')
->createBuilder('\\User')
->getPagerfanta('my query');
License
The work is provided as is for free without any support guarantee under the Creative Commons CC-BY-SA license.
Author
The work was made by Oleg Stepura. If you have questions feel free to contact me at github [-at-] oleg.stepura.com
olegstepura/doctrine-multicolumn-search 适用场景与选型建议
olegstepura/doctrine-multicolumn-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 5, 最近一次更新时间为 2012 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 olegstepura/doctrine-multicolumn-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 olegstepura/doctrine-multicolumn-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2012-03-17