Skip to content

启用全文搜索功能

管宜尧 edited this page May 23, 2022 · 2 revisions

在最新的 1.3.0 版本中增加了全文检索的支持,默认情况下,全文检索功能是关闭的,如果要启用,需要配合第三方搜索引擎,目前 Wizard 支持以下几种搜索引擎

通过在 .env 配置文件或者环境变量中添加配置项 WIZARD_SEARCH_DRIVER 来启用不同的搜索引擎,如 WIZARD_SEARCH_DRIVER=App\Components\Search\ElasticSearchDriver,支持以下搜索引擎配置

  • ElasticSearch:App\Components\Search\ElasticSearchDriver
  • ZincSearch: App\Components\Search\ZincSearchDriver
  • GoFoundSearch:App\Components\Search\GoFoundDriver
  • 默认数据库模糊匹配:App\Components\Search\NullDriver

初次启用时,需要执行以下命令来导入已有的文档到搜索引擎

php artisan sync-index:document

ElasticSearch

配置 默认值 备注
WIZARD_ES_SERVER http:https://localhost:9200 服务器地址
WIZARD_ES_INDEX wizard 索引名称
WIZARD_ES_USERNAME - 用户名
WIZARD_ES_PASSWORD - 密码

ZincSearch

配置 默认值 备注
WIZARD_ZINC_SERVER http:https://localhost:4080 服务器地址
WIZARD_ZINC_INDEX wizard 索引名称
WIZARD_ZINC_USERNAME - 用户名
WIZARD_ZINC_PASSWORD - 密码
WIZARD_ZINC_SEARCH_TYPE matchphrase 搜索方式

搜索方式支持以下值:alldocuments,wildcard,fuzzy,term,daterange,matchall,match,matchphrase,multiphrase,prefix,querystring

参考文档: https://docs.zincsearch.com/API%20Reference/search/1_search/

GoFoundSearch

配置 默认值 备注
WIZARD_GOFOUND_SERVER http:https://localhost:5678 服务器地址
WIZARD_GOFOUND_DATABASE wizard 数据库名称
WIZARD_GOFOUND_USERNAME - 用户名
WIZARD_GOFOUND_PASSWORD - 密码