peterujah/php-search-controller
Composer 安装命令:
composer require peterujah/php-search-controller
包简介
Php advance mysql database search to perform search operations.
关键字:
README 文档
README
PHPSearchController is a simple PHP class to search MySQL database, it can build SQL queries to perform MySQL database searches by taking parameters that define database table fields and field values to search.
The class generates SQL conditions used to build SQL queries to perform database searches for records that match the criteria based on the table fields and field values defined by the parameters, It then combines several conditions using SQL operators such as AND, OR, NAND, LIKE NOR & FIND_IN_SET and return the appropriate queries for the search.
Installation
Installation is super-easy via Composer:
composer require peterujah/php-search-controller
Usages
Initialize the class with your preferred search method the default method is SearchController::OR.
use Peterujah\NanoBlock\SearchController; $search = new SearchController();
Set your preferred search operator the default is SearchController::END_WITH_QUERY.
$search->setOperators(SearchController::HAVE_ANY_QUERY);
To perform a database search, you can just build your search query like the one below.
$searchQuery = "PHP Code"; $search->setQuery($searchQuery)->split(); $search->setParameter(array( 'code_title', 'code_description', 'code_info' )); //var_export($search->getQuery());
To search by tag using MySQL FIND_IN_SET, build a query like the example below.
$searchQuery = "PHP Code"; $search->setQuery($searchQuery)->split(); $search->setTags("code_tags"); //var_export($search->getQuery());
Set the initial query and pass the search query to your MySQL connection
$search->setIniQuery("SELECT * FROM code WHERE id = 1323"); $db->conn()->prepare($search->getQuery()); $db->conn()->execute(); $result = $db->conn()->getAll(); $db->conn()->free();
OR build it with other sql queries like the below in your MySQL connection
$db->conn()->prepare(" SELECT * FROM code {$search->getQuery()} AND id = 1323 "); $db->conn()->execute(); $result = $db->conn()->getAll(); $db->conn()->free();
Other Methods
Returns the computed sql search queries by checking if the initial query was specified or not to determine which start clause is needed.
$search->getQuery()
Set your search keyword
$search->setQuery("Foo Bar")
Split search keyword Foo Bar into Foo, Bar as separate search terms
$search->split()
Mapping your database column keys to perform a search on
$search->setParameter(array)
Set the initial SQL query before appending the search after your query string
$search->setIniQuery('SELECT * FROM ...')
Reference
Specify search operator $search->setOperators(SearchController::HAVE_ANY_QUERY)
| Search Operators | Description |
|---|---|
| START_WITH_QUERY | Finds any values that start with "query" |
| END_WITH_QUERY | Finds any values that end with "query" |
| HAVE_ANY_QUERY | Finds any values that have "query" in any position |
| HAVE_SECOND_QUERY | Finds any values that have "query" in the second position |
| START_WITH_QUERY_2LENGTH | Finds any values that start with "query" and are at least 2 characters in length |
| START_WITH_QUERY_3LENGTH | Finds any values that start with "query" and are at least 3 characters in length |
| START_END_WITH_QUERY | Finds any values that start with "query" and ends with "query" |
Initialize search class with a method new SearchController(SearchController::OR)
| Search Methods | Description |
|---|---|
| OR | Retrieve result with any one of search query |
| AND | Retrieve result with the exact of search quer |
| NAND | Retrieve result without the exact search query |
| NOR | Retrieve result without any on of the search query |
peterujah/php-search-controller 适用场景与选型建议
peterujah/php-search-controller 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「library」 「search」 「php search」 「mysql search」 「sql search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 peterujah/php-search-controller 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 peterujah/php-search-controller 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 peterujah/php-search-controller 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Abstraction Layer to index and search entities
Inbox pattern process implementation for your Laravel Applications
Pimcore 10.x Website Indexer (powered by Zend Search Lucene)
Core library that defines common interfaces used by the rest of the intahwebz..
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-14