traore225/laravel-smart-search
最新稳定版本:v1.0.1
Composer 安装命令:
composer require traore225/laravel-smart-search
包简介
A lightweight, configurable, scoring-based search engine for Laravel with FULLTEXT support and automatic fallback.
README 文档
README
A lightweight, configurable, scoring-based search engine for Laravel.
Laravel Smart Search provides:
- Exact match priority
- Weighted scoring system
- FULLTEXT support (MySQL/MariaDB)
- Automatic fallback to LIKE search
- Configurable columns
- Safe FULLTEXT detection (no crashes)
- Optional fallback disabling per request
Installation
Install via Composer:
composer require traore225/laravel-smart-search
Requirements
- PHP 8.1+
- Laravel 10+ / 11+
- MySQL or MariaDB recommended for FULLTEXT support
Publish Configuration
php artisan vendor:publish --tag=smart-search-config
This creates:
config/smart-search.php
FULLTEXT Setup (Recommended)
Generate a migration for your FULLTEXT index:
php artisan smart-search:make-index --table=posts --columns=title php artisan migrate
Check if FULLTEXT is installed:
php artisan smart-search:install --table=posts --column=title
If you prefer to add it manually:
ALTER TABLE posts ADD FULLTEXT (title);
FULLTEXT is optional but recommended for performance. Smart Search automatically detects if FULLTEXT is available and safely disables it if missing.
Basic Usage
use Traore225\LaravelSmartSearch\Search\SearchEngine; $engine = app(SearchEngine::class); $query = \App\Models\Post::query(); $query = $engine->apply($query, [ 'description' => 'ps3 controller', ]); $results = $query->paginate();
Disable Fallback (Per Request)
$query = $engine->apply($query, [ 'description' => 'ps3 controller', 'fallback' => false, ]);
Configuration Example
return [ 'max_title_tokens' => 3, 'columns' => [ 'title' => 'title', 'description' => 'description', ], 'fulltext' => [ 'enabled' => true, 'multiplier' => 10, ], 'weights' => [ 'exact_title' => 1000000, 'title_word_base' => 4000, 'title_word_step' => 500, 'title_cumulative_base' => 3000, 'title_cumulative_step' => 300, ], 'fallback' => [ 'enabled' => true, 'min_words' => 2, 'fields' => ['title', 'description'], ], ];
How It Works
Priority order:
- Exact match
- Weighted LIKE scoring
- FULLTEXT boolean scoring (if available)
- Fallback LIKE search (if enabled)
FULLTEXT is auto-detected and safely disabled when the index is missing.
Database Support
| Database | Support |
|---|---|
| MySQL | Full |
| MariaDB | Full |
| PostgreSQL | LIKE fallback only |
| SQLite | LIKE fallback only |
Performance
- FULLTEXT auto-detected and cached
- No crash if index is missing
- Minimal overhead
- No external dependencies
License
MIT License © 2026 Traore Sidiki
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-18