brokerexchange / elasticscout
Laravel Scout Driver for Elasticsearch 6 and 7
v10.1.0
2019-08-16 13:54 UTC
Requires
- elasticsearch/elasticsearch: ^6.0|^7.0
- laravel/scout: ^7.0
- v10.1.0
- 10.0.x-dev
- v10.0.0
- v9.2.1
- v9.2.0
- v9.1.0
- 9.0.x-dev
- v9.0.2
- v9.0.1
- v9.0.0
- 8.0.x-dev
- v8.0.0
- 7.0.x-dev
- v7.0.1
- v7.0.0
- 6.0.x-dev
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- 5.0.x-dev
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.2
- v3.0.1
- v3.0.0
This package is auto-updated.
Last update: 2024-09-17 01:06:59 UTC
README
ElasticScout
Elasticsearch 6 的 Laravel Scout 驱动
概述
ElasticScout 是一个与 Elasticsearch 6 兼容的 Laravel Scout 引擎。它对旧的 Elasticseach Scout Engine 进行了关键性的修改,并增加了新功能。
ElasticScout 引擎包括一个 Elasticsearch Query Builder,可用于创建复杂的自定义查询和聚合,允许在 Laravel/Scout 体系结构内充分利用 Elasticsearch。
许可
ElasticScout 在 MIT 开源许可证下发布,https://open-source.org.cn/licenses/MIT
版权
ElasticScout © Broker Exchange Network 2018
安装
- 运行 composer require 命令
composer require brokerexchange/elasticscout
- 配置 Elasticsearch 主机(默认:localhost:9200)
ELASTICSEARCH_HOST='elastic1.host.com:9200,elastic2.host.com:9200'
- 将特质添加到所需模型中
use ElasticScout\Searchable;
用法
//create search/query object $search = $article->search() ->boolean() ->should(DSL::match('title',$request->input('query'))) ->should(DSL::match('body',$request->input('query'))) ->highlight(['body','title']) ->filter(DSL::term('published', 1)) ->aggregate(Agg::terms('categories', 'category.name')); //fire the search $articles = $search->paginate(); //retrieve aggregation results $categories = $search->aggregation('categories'); //retrieve highlight results for title field of first result article $firstArticleTitleHighlights = $articles->first()->highlight('title');
映射
您可以通过在模型上定义 "mapping" 方法来设置自定义映射。
public function mappings() { return [ $this->searchableType() => [ 'properties' => [ 'name' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', ], 'autocomplete' => [ 'type' => 'text', 'analyzer' => 'autocomplete', 'search_analyzer' => 'autocomplete_search', ], ], ], ] ] ] }
设置
您可以在模型上创建 "settings" 方法来创建自定义设置和分析器。
public function settings() { return [ 'index' => [ 'analysis' => [ 'analyzer' => [ 'autocomplete' => [ 'tokenizer' => 'autocomplete', 'filter' => [ 'lowercase', ], ], 'autocomplete_search' => [ 'tokenizer' => 'lowercase', ], ], 'tokenizer' => [ 'autocomplete' => [ 'type' => 'edge_ngram', 'min_gram' => 1, 'max_gram' => 15, 'token_chars' => [ 'letter' ] ] ] ], ], ]; }