使用Laravel5.3中的Scout,默认搜索是algolia,对中文的支持好吗? 财富值61

2016-09-29 07:49发布

使用Laravel5.3中的Scout,默认搜索是algolia,它对中文的支持好吗?

如果要使用elasticsearch,要自己写什么东西?

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
1条回答
mishen - whatsns产品经理
1楼-- · 2016-10-09 09:37

说明

Laravel 5.3 发布临近,大体构建已经完成,文档整理完成后即可发布。

下面是对 Laravel 5.3 新特性的整理,不完整列表。

1、全文搜索 Laravel Scout

Laravel Scout 是针对 Eloquent 开发的基于驱动的全文搜索方案,默认集成了对 Algolia 搜索服务 的支持,由于它是基于驱动的,你可以通过它集成任何其它搜索引擎。

Scout 通过在已有模型上实现 "Searchable" trait 来实现搜索功能,然后只需同步数据到搜索服务即可:

php artisan scout:import App\\Post

之后就可以通过以下方式进行搜索:

Post::search('Alice')->get();

还可以对结果进行分页:

Post::search('Alice')->paginate();

甚至是支持简单的 where 条件语句:

Post::search(‘Alice’)—>where('acount_id', '>', 1)->paginate();

2、邮件操作 Laravel Mailable

Laravel Mailable 是一个崭新的 Mail 操作类,通过一种更加优雅的方式发送邮件:

Mail::to('laravel@example.com')->send(new OrderComplete);

当然,还支持其他所有邮件功能:

Mail::to('laravel@example.com')
            ->cc('john@example.com')
            ->queue(new OrderComplete);

3、消息通知系统 Laravel Notifications

Laravel Notifications 允许你通过 Slack、短信或者邮件等服务实现快速更新。

Notifications 附带了一个响应式邮件模板,通知类中唯一需要做的就是像下面这样发送消息:

$this->line('Thank you for joining')
    ->action('Button Text', 'http://url.com')
    ->line('If you have any questions please hit reply')
    ->success()

错误处理:

$this->line('Sorry we had a problem with your order')
    ->action('Button Text', 'http://url.com')
    ->error()

4、Laravel Passport

Laravel Passport 是一个可选的扩展包,提供了完整可用的 oAuth 2 服务。

你可以自己设置 scope、Vue.js 模块以便执行生成、撤回 token 等操作。

5、回溯一个迁移

新功能允许你回溯一个迁移文件,之前只能回溯 最后执行的一次 的迁移(一次又多个迁移文件)。

php artisan migrate:rollback --step=1

6、Blade 里的 $loop 变量

你可以在 foreach 循环中使用魔术变量 $loop :

@if($loop->first)
    Do something on the first iteration.@endif@if($loop->last)
    Do something on the last iteration.@endif

7、Eloquent firstOrCreate

例子:使用 GitHub 登录时检查 GitHub ID 是否存在,如果不存在并且你创建了新用户的话,你想要保存用户的头像:

之前这么做:

$user = User::firstOrNew(['github_id', $githubUser->id]);if (! $user->exists) {    $user->fill(['avatar' => $githubUser->avatar])->save();
}return $user;

使用 firstOrCreate:

return User::firstOrCreate(['github_id', $githubUser->id], ['avatar' => $githubUser->avatar]);

8、路由存放路径改变

之前所有路由默认存放在 app/Http/routes.php 单一文件里,现在转移到根目录 routes/ 里的 web.php 和 api.php 两个文件中。

9、App 文件夹结构改变

10、查询语句构造器永远返回集合

之前 get 返回的是数组,以后统一返回集合:

$collection = DB::table('posts')->get();

11、支持自定义迁移路径

$this->loadMigrationsFrom('path/to/migrations/folder')