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.phpprovider 中添加

//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

如图所示
file

更详细内容强查看 https://github.com/zizohassan/full-text-search-laravel

本作品采用《CC 协议》,转载必须注明作者和本文链接
持续做一件事,必定有所成就
本帖由 Summer 于 7年前 加精
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 3
wanghan

支持!

7年前 评论

@jl9404 你可以去给他修正 :laughing:

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!