定制 sharifuddin/laravel-smart-search 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sharifuddin/laravel-smart-search

Composer 安装命令:

composer require sharifuddin/laravel-smart-search

包简介

A smart search helper for Laravel. Provides advanced Eloquent search with relation discovery and multiple search modes.

README 文档

README

Laravel Smart Search is a high-performance, intelligent search package for Laravel Eloquent models. It provides automatic relation discovery, configurable search depth, multiple search modes, and optimized queries for large datasets.

✨ Key Features

  • 🔍 Smart Relation Discovery – Automatically searches through model relationships.
  • High Performance – Optimized queries with configurable limits.
  • 🎯 Multiple Search Modeslike, exact, starts_with, ends_with.
  • 🔧 Fully Configurable – Customize search behavior and priorities.
  • 📚 Priority Columns – Define columns to prioritize for better results.
  • 🛡️ Type Safe – Full type hints, PHPStan ready.
  • 🧪 Fully Tested – Comprehensive test coverage included.
  • 🔌 Laravel Native – Seamless integration with Eloquent models.

📦 Installation

Requirements

  • PHP 8.1+
  • Laravel 10.x or 11.x

Via Composer

composer require sharif/laravel-smart-search

``

Publish Configuration (Optional)

php artisan vendor:publish --provider="Sharifuddin\\LaravelSmartSearch\\SmartSearchServiceProvider" --tag="smart-search-config"

🎯 Quick Start

1️⃣ Use the Trait

Add the SmartSearch trait to your Eloquent models:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Sharifuddin\LaravelSmartSearch\Traits\SmartSearch;

class Product extends Model
{
    use SmartSearch;
}

2️⃣ Basic Search Usage

// Simple search
$products = Product::applySmartSearch('laptop')->get();

// Paginated search
$products = Product::applySmartSearch($request->input('search'))->paginate(15);

// Search with relations
$products = Product::applySmartSearch('apple')->with('brand', 'categories')->get();

🔧 Configuration

After publishing, edit config/smart-search.php to customize behavior:

return [
    'defaults' => [
        'mode' => 'like',
        'deep' => true,
        'max_relation_depth' => 2,
        'search_operator' => 'or',
    ],

    'columns' => [
        'excluded' => [
            'id', 'created_at', 'updated_at', 'deleted_at',
            'password', 'remember_token', 'email_verified_at'
        ],
        'prioritized' => ['name', 'title', 'code', 'email'],
        'max_per_table' => 10,
    ],

    'relations' => [
        'auto_discover' => true,
        'max_depth' => 2,
        'excluded' => ['password', 'secret', 'tokens'],
    ],

    'performance' => [
        'max_join_tables' => 5,
        'chunk_search' => false,
        'chunk_size' => 1000,
    ],
];

💡 Usage Examples

Basic Search

$users = User::applySmartSearch('john')->get();
$products = Product::applySmartSearch('wireless keyboard')->paginate(20);

Advanced Search with Options

$results = Product::applySmartSearch(
    search: 'laptop',
    columns: ['name', 'sku', 'description'],
    options: [
        'mode' => 'like',
        'deep' => true,
        'max_relation_depth' => 1
    ]
)->get();

Relation Search

$posts = Post::applySmartSearch('laravel tips')->with('author', 'tags', 'comments')->get();

Multiple Search Modes

// Like (default)
$results = Product::applySmartSearch('phone');

// Exact match
$results = User::applySmartSearch('admin@example.com', [], ['mode' => 'exact']);

// Starts with
$results = Product::applySmartSearch('APP', [], ['mode' => 'starts_with']);

// Ends with
$results = Product::applySmartSearch('001', [], ['mode' => 'ends_with']);

⚡ Performance Optimization

  • Add indexes for frequently searched columns.
  • Limit max_relation_depth for large datasets.
  • Disable deep option for simple queries.
  • Enable chunk_search in config for large tables.

🧪 Testing

# Run all tests
composer test

# Run tests with coverage
composer test-coverage

🤝 Contributing

  1. Fork the repository.
  2. Clone your fork: git clone https://github.com/your-username/laravel-smart-search.
  3. Install dependencies: composer install.
  4. Run tests: composer test.

See CONTRIBUTING.md for more details.

📄 License

MIT License. See LICENSE.md.

Laravel Smart Search - Intelligent search for intelligent applications.

GitHubPackagistIssuesDiscussions

```

sharifuddin/laravel-smart-search 适用场景与选型建议

sharifuddin/laravel-smart-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「search」 「filter」 「laravel」 「relations」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sharifuddin/laravel-smart-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sharifuddin/laravel-smart-search 我们能提供哪些服务?
定制开发 / 二次开发

基于 sharifuddin/laravel-smart-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-01