sgloe/multi-search-bundle
Composer 安装命令:
composer require sgloe/multi-search-bundle
包简介
Symfony bundle for Multi Criteria Search for doctrine entities using Form or Service.
README 文档
README
This bundle provides basic service and form type for Multi Search in Doctrine.
Description
Search in all of entity columns by given search term.
In response returns Doctrine\ORM\QueryBuilder containing the multiple search criteria.
The searched columns can be specified.
Installation
Using composer
composer require sgloe/multi-search-bundle
Add it to your config/bundles.php:
Sgloe\MultiSearchBundle\SgloeMultiSearchBundle::class => ['all' => true],
Usage
Service
You can inject the service and apply the multi search to any Doctrine query builder.
use Sgloe\MultiSearchBundle\Service\MultiSearchBuilderService;
public function __construct(
private MultiSearchBuilderService $multiSearchBuilder,
private EntityManagerInterface $entityManager,
) {}
public function index(Request $request): Response
{
$search = $request->query->get('search');
$qb = $this->entityManager->getRepository(Post::class)->createQueryBuilder('e');
$qb = $this->multiSearchBuilder->searchEntity($qb, Post::class, $search);
//$qb = $this->multiSearchBuilder->searchEntity($qb, Post::class, $search, ['name', 'content'], 'wildcard');
..
}
Form
Create your form type and include the multiSearchType in the buildForm function:
use Sgloe\MultiSearchBundle\Form\Type\MultiSearchType;
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('search', MultiSearchType::class, [
'class' => Post::class, //required
'search_fields' => [ //optional, if it's empty it will search in all entity columns
'name',
'content',
],
'search_comparison_type' => 'wildcard', //optional, what type of comparison to apply ('wildcard','starts_with', 'ends_with', 'equals')
])
;
}
In the controller, inject the service and call the multi search:
use Sgloe\MultiSearchBundle\Service\MultiSearchBuilderService;
public function __construct(
private MultiSearchBuilderService $multiSearchBuilder,
private EntityManagerInterface $entityManager,
) {}
public function index(Request $request): Response
{
$queryBuilder = $this->entityManager->getRepository(Post::class)->createQueryBuilder('e');
$filterForm = $this->createForm(PostFilterType::class);
// Bind values from the request
$filterForm->handleRequest($request);
if ($filterForm->isSubmitted() && $filterForm->isValid()) {
// Build the query from the given form object
$queryBuilder = $this->multiSearchBuilder->searchForm($queryBuilder, $filterForm->get('search'));
}
..
}
Render your form in the view
{{ form_rest(filterForm) }}
Available Options
The provided type has 2 options:
-
search_fields- array of the entity columns that will be added in the search. If it's not set then will search in all columns -
search_comparison_type- how to compare the search term.-
wildcard- it's equivalent to the %search% like search. -
equals- like operator without wildcards. Wildcards still can be used withequalsif the search term contains *. -
starts_with- it's equivalent to the %search like search. -
ends_with- it's equivalent to the search% like search.
-
These parameters can be applyed to the service as well as 4th and 5th parameter to searchEntity() method
Author
Sgloe
Thanks to Petko Petkov, who originally wrote this bundle. Since it is not maintained anymore, I started this fork.
License
MultiSearchBundle is licensed under the MIT License.
sgloe/multi-search-bundle 适用场景与选型建议
sgloe/multi-search-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「doctrine」 「query builder」 「criteria」 「multi-search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sgloe/multi-search-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sgloe/multi-search-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sgloe/multi-search-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Query filtering in your frontend
Anax Database Active Record module for model classes.
Make pimcore migration simple
Database/ORM-agnostic query construction helper
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-28