Laravel 5.4 FULLTEXT 全文索引的扩展包
Laravel 5.4 FULLTEXT
全文索引的扩展包
github
地址
https://github.com/zizohassan/full-text-search-laravel
1. 安装
composer require 5dmatwebsearch/advancesearch:dev-master
Search
语法
Search::search(modelName , feilds, searchText ,select , order , pagination , limit)
2. 注册
config/app.php
的 provider
中添加
//full text search
AdvanceSearch\AdvanceSearchProvider\AdvanceSearchProvider::class,
在aliases
中添加
//full text
'Search' => AdvanceSearch\AdvanceSearchProvider\Facades\SearchFacades::class,
3. Views
添加 resources/views/search.blade.php
<form action="/search" method="post">
{{ csrf_field() }}
<input type="text" name="search">
<input type="submit" value="search">
</form>
4. 数据
数据表迁移文件
php artisan make:migration create_films_table --create=films
修改内容
Schema::create('films', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('intro');
$table->text('dec');
$table->text('content');
$table->timestamps();
});
执行数据库迁移
php artisan migrate
添加测试数据
php artisan tinker
>>> factory(App\Film::class,200)->create();
创建FULLTEXT
php artisan index:table films title,intro
5. MODEL
创建Model
php artisan make:model Film
6. 路由
在路由中添加测试
Route::get('/', function () {
return view('search');
});
Route::post('search',function(\Illuminate\Http\Request $request){
dd(Search::search(
"Film" ,
['title','intro'] ,
$request->search ,
['id' , 'title' , 'intro' ,'dec'] ,
['id' ,'desc'] ,
true ,
30
));
});
7. 测试
启动laravel服务器
php artisan serve
如图所示
更详细内容强查看 https://github.com/zizohassan/full-text-search-laravel
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由 Summer
于 7年前 加精
支持!
https://github.com/zizohassan/full-text-se...
安全問題? :smile:
@jl9404 你可以去给他修正 :laughing: