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: 2025-03-07 03:24:05 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 擴展