filippo-toso/fulltext
最新稳定版本:v1.1.2
Composer 安装命令:
composer require filippo-toso/fulltext
包简介
Easily add fulltext search capabilities to your Eloquent models
README 文档
README
A simple way to add fulltext capabilities to your Eloquent models (just for MySQL for the moment).
Requirements
- PHP 5.6+
- Laravel 5.0+
Installing
Use Composer to install it:
composer require filippo-toso/fulltext
Using It
Create a fulltext index in your migrations:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use FilippoToso\Fulltext\FullText;
class AddIndexesToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create a fulltext index in the users table for the first_name and last_name columns
FullText::fullTextIndex('users', ['first_name', 'last_name']);
// You can also specify a name for the index with the third parameter
FullText::fullTextIndex('users', ['city', 'address', 'country'], 'search_address');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropIndex(['first_name', 'last_name']);
$table->dropIndex('search_address');
});
}
}
Enable fulltext functions within the User model (for instance):
namespace App;
use Illuminate\Database\Eloquent\Model;
use FilippoToso\FullText\Traits\FullText;
class User extends Model
{
use FullText;
}
Use the FullText trait's features:
// Use the whereMatch() scope to search for all users named "filippo"
$users = App\User::select('*')
->whereMatch(['first_name', 'last_name'], 'filippo')
->get();
// Include in the result the score column with the matching score
$users = App\User::select('*')
->whereMatch(['first_name', 'last_name'], 'filippo')
->selectMatchScore(['first_name', 'last_name'], 'filippo')
->get();
// You can also include the name of the score column with the third parameter of selectMatchScore()
$users = App\User::select('*')
->whereMatch(['first_name', 'last_name'], 'filippo')
->selectMatchScore(['first_name', 'last_name'], 'filippo', 'matching_score')
->get();
统计信息
- 总下载量: 976
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-12