Skip to content

Commit

Permalink
README.md 添加 lumen 配置项说明 调整文档顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
vanry committed Feb 23, 2020
1 parent b2fcf3d commit eb2a037
Showing 1 changed file with 59 additions and 56 deletions.
115 changes: 59 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
composer require vanry/laravel-scout-tntsearch
```

### Laravel
#### Laravel

`Laravel` 具有包自动发现功能,不用手动添加服务提供者。

Expand All @@ -19,13 +19,13 @@ composer require vanry/laravel-scout-tntsearch
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
```

如果要修改 `tntsearch` 默认配置,也可发布 `tntsearch` 配置文件
如需修改 `tntsearch` 默认配置,也可发布 `tntsearch` 配置文件

```bash
php artisan vendor:publish --provider="Vanry\Scout\TNTSearchScoutServiceProvider"
```

### Lumen
#### Lumen

`Lumen` 需将服务提供者添加到 `bootstrap/app.php`

Expand All @@ -40,73 +40,29 @@ $app->register(Vanry\Scout\LumenServiceProvider::class);
$app->register(Laravel\Scout\ScoutServiceProvider::class);
```

### 启用
`laravel scout` 配置文件 `scout.php` 复制到项目根目录下的 `config` 目录下,不存在就创建。

如需修改 `tntsearch` 默认配置,则将配置文件 `tntsearch.php` 复制到项目根目录下的 `config` 目录下。

#### 启用

`.env` 文件中添加

```bash
SCOUT_DRIVER=tntsearch
```


## 用法

* 添加 `Searchable Trait` 到模型

```php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class Post extends Model
{
use Searchable;

/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();

// Customize array...

return $array;
}
}
```

* 同步数据到搜索索引

```php
# scout 命令
php artisan scout:import App\\Post

# tntsearch 命令, 性能更好
php artisan tntsearch:import App\\Post
```


* 使用模型进行搜索

```php
Post::search('laravel教程')->get();
```

## 中文分词

目前支持 `scws`, `jieba``phpanalysis` 中文分词。

### 对比
#### 对比

* `scws` 是用 `C` 语言编写的 `php` 扩展,性能最佳,分词效果好,但不支持 `Windows` 系统。
* `jieba``python` 版本结巴分词的 `php` 实现,分词效果最好,尤其是新词发现,不足之处是性能较差,占用内存大。
* `phpanalysis``php` 编写的一款轻量分词器,分词效果不错,性能介于 `scws``jieba` 两者之间。

### 安装
#### 安装

- **scws**

Expand All @@ -126,7 +82,7 @@ composer require fukuball/jieba-php
composer require lmz/phpanalysis
```

### 配置
#### 配置

`.env` 文件中配置

Expand All @@ -136,7 +92,7 @@ TNTSEARCH_TOKENIZER=scws

> 可选值为 `default`, `scws`, `jieba`, `phpanalysis`, 其中 `default``TNTSearch` 自带的分词器。
### 问题
#### 问题

使用 `jieba` 分词可能会出现内存分配不足的错误信息:

Expand All @@ -148,6 +104,53 @@ TNTSEARCH_TOKENIZER=scws
ini_set('memory_limit', '1024M');
```

## 用法

* 添加 `Searchable Trait` 到模型

```php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class Post extends Model
{
use Searchable;

/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();

// Customize array...

return $array;
}
}
```

* 同步数据到搜索索引

```php
# scout 命令
php artisan scout:import App\\Post

# tntsearch 命令, 性能更好
php artisan tntsearch:import App\\Post
```


* 使用模型进行搜索

```php
Post::search('laravel教程')->get();
```

## 高亮

`view composer` 中引入 `highlighter`, 可使用以上任一分词器。
Expand Down

0 comments on commit eb2a037

Please sign in to comment.