hallelujahbaby / laravel-scout-tntsearch-driver-chinese
配合SCWS中文分词功能的 Laravel Scout TNTSearch 驱动包
v6.1.2
2019-01-29 15:10 UTC
Requires
- php: >=7.0
- hallelujahbaby/scws: ^1.0
- illuminate/bus: ~5.4
- illuminate/contracts: ~5.4
- illuminate/database: ~5.4
- illuminate/pagination: ~5.4
- illuminate/queue: ~5.4
- illuminate/support: ~5.4
- laravel/scout: 6.*
- teamtnt/tntsearch: 1.4.*
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5.0
Suggests
- hallelujahbaby/scws: Required to use the SCWS extension
- teamtnt/tntsearch: Required to use the TNTSearch engine.
- v6.1.2
- v6.1.1
- v3.3.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- dev-master / 1.0.x-dev
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-analysis-86331W
- dev-analysis-8LmWkw
- dev-analysis-q1kD5w
- dev-analysis-qJD9xn
- dev-analysis-zY69Qj
- dev-analysis-8Pe7EL
- dev-analysis-z3GJ69
This package is auto-updated.
Last update: 2024-09-07 01:48:24 UTC
README
原版:https://github.com/teamtnt/laravel-scout-tntsearch-driver
安装
通过 composer 安装
composer require JT501/laravel-scout-tntsearch-driver-chinese
(Laravel 5.5 以下版本) 将服务提供者添加到 config/app.php
'providers' => [ // ... Laravel\Scout\ScoutServiceProvider::class, TeamTNT\Scout\TNTSearchScoutServiceProvider::class, ],
在 .env 文件中添加
SCOUT_DRIVER=tntsearch
然后就可以将 scout.php 配置文件发布到 config 目录。
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
在 config/scout.php 中添加
'tntsearch' => [ 'storage' => storage_path('TNTSearch'), //place where the index files will be stored 'fuzziness' => env('TNTSEARCH_FUZZINESS', false), 'fuzzy' => [ 'prefix_length' => 2, 'max_expansions' => 50, 'distance' => 2 ], 'asYouType' => false, 'searchBoolean' => env('TNTSEARCH_BOOLEAN', false), 'tokenizer' => [ 'scws' => [ 'charset' => 'utf-8', 'dict' => '/usr/local/scws/etc/dict.utf8.xdb', // SCWS 詞典路徑 'add_dict' => '/usr/local/scws/etc/dict_cht.utf8.xdb', // 加入額外詞典到 SCWS 'rule' => '/usr/local/scws/etc/rules_chts.utf8.ini', // SCWS 規則路徑 'multi' => false, 'ignore' => true, 'duality' => false, ], ], 'stopwords' => [ 'a', 'as', 'the', '的', '了', '而是', ], ],
你还可以在模型中直接添加 asYouType 选项,参考下面的示例。
用法
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Laravel\Scout\Searchable; class Post extends Model { use Searchable; public $asYouType = true; /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray() { $array = $this->toArray(); // 自定可搜索的Array return $array; } }
同步数据到搜索服务
php artisan scout:import App\\Post
使用模型进行搜索
Post::search('你好世界')->get();
安装中文分词
目前默认只支持 scws 中文分词。需要安装 SCWS 扩展包 和 SCWS PHP 扩展