Download the PHP package skywit/laravel-scout-tntsearch without Composer
On this page you can find all versions of the php package skywit/laravel-scout-tntsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-scout-tntsearch
说明:
2.x版本只支持Laravel 5.5以上版本,Laravel 5.5以下版本请使用 1.x版本。
安装
需安装并开启
sqlite扩展
Laravel
-
发布
scout配置文件,已安装scout可省略。 - 如需修改
tntsearch默认配置,发布tntsearch配置文件。
Lumen
Lumen 需将服务提供者添加到 bootstrap/app.php
在根目录中创建 config 文件夹, 将 laravel scout 配置文件 scout.php 复制到 config 中。
如需修改 tntsearch 默认配置,则将配置文件 tntsearch.php 复制 config 中进行修改。
启用
在 .env 文件中添加
用法
-
模型添加
Searchable Trait -
导入模型 创建索引
- 使用索引进行搜索
中文分词
目前支持 scws, jieba 和 phpanalysis 中文分词,默认使用 phpanalysis 分词。
对比
scws是用C语言编写的php扩展,性能最好,分词效果好,但不支持Windows系统。jieba为python版本结巴分词的php实现,分词效果最好,尤其是新词发现,不足之处是性能较差,占用内存大。phpanalysis是php编写的一款轻量分词器,分词效果不错,性能介于scws和jieba两者之间。
安装
使用 scws 或者 jieba,需安装对应的分词驱动。
-
scws
- jieba
在 .env 文件中配置
问题
使用 jieba 分词可能会出现内存分配不足的错误信息:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
在代码中增加内存限制即可
高亮
默认使用 em 作为高亮 html 标签,在 css 中设置高亮样式即可,也可以自定义高亮标签。
- @highlight 指令
- $text: 要高亮的字段
- $query: 搜索词
- $tag: 高亮的 html 标签
-
highlight 帮助函数
- Highlighter 对象
highlight帮助函数和Highlighter对象适合在api等非html视图中使用。
All versions of laravel-scout-tntsearch with dependencies
illuminate/console Version ~5.5|^6.0|^7.0|^8.0
illuminate/database Version ~5.5|^6.0|^7.0|^8.0
illuminate/support Version ~5.5|^6.0|^7.0|^8.0
illuminate/view Version ~5.5|^6.0|^7.0|^8.0
laravel/scout Version ^6.0|^7.0|^8.0
lmz/phpanalysis Version ^1.0
teamtnt/tntsearch Version ^2.0