Package Data | |
---|---|
Maintainer Username: | Artistan |
Maintainer Contact: | brian@brokerbin.com (Brian Mix) |
Package Create Date: | 2016-11-03 |
Package Last Update: | 2019-08-16 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-11 15:06:16 |
Package Statistics | |
---|---|
Total Downloads: | 793 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 17 |
Total Watchers: | 8 |
Total Forks: | 6 |
Total Open Issues: | 0 |
A Laravel Scout Driver for Elasticsearch 6
ElasticScout is a Laravel Scout Elasticsearch 6 compatible engine. It makes critical changes to the old Elasticseach Scout Engine, as well as adds new functionality.
The ElasticScout engine includes an Elasticsearch Query Builder which can be used to create elaborate custom queries and aggregations, allowing full use of Elasticsearch within the Laravel/Scout Paradigm.
ElasticScout is released under the MIT Open Source License, https://opensource.org/licenses/MIT
ElasticScout © Broker Exchange Network 2018
composer require brokerexchange/elasticscout
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');
You may set a custom mapping by simply defining a "mapping" method on your model.
public function mappings()
{
return [
$this->searchableType() => [
'properties' => [
'name' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword',
],
'autocomplete' => [
'type' => 'text',
'analyzer' => 'autocomplete',
'search_analyzer' => 'autocomplete_search',
],
],
],
]
]
]
}
You may create custom settings and analyzers by creating a "settings" method on the model.
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'
]
]
]
],
],
];
}