Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Feat: PHP-8.1 support and Laravel scout 9.0 support (#163)
Browse files Browse the repository at this point in the history
* Feat: PHP-8.1 support and laravel scout 9.0 support

* Feat: Add Laravel scout 9.3 support

Co-authored-by: Santosh Jung Shahi <[email protected]>
  • Loading branch information
beingjungshahi and Santosh Jung Shahi authored Dec 31, 2021
1 parent 058a3fc commit 9e6300e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
"elastic"
],
"require": {
"php": "^7.2|^8.0",
"laravel/scout": "^8.0"
"php": "^7.2|^8.0|^8.1",
"laravel/scout": "^9.3"
},
"require-dev": {
"elasticsearch/elasticsearch": "^7.9",
"fzaninotto/faker": "~1.9.1",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0|^9.3"
},
Expand Down
29 changes: 29 additions & 0 deletions src/Engines/ElasticsearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ public function __construct(Elastic $elastic)
$this->elastic = $elastic;
}

public function lazyMap(Builder $builder, $results, $model)
{
return Collection::make($results['hits']['hits'])->map(function ($hit) use ($model) {
return $model->newFromBuilder($hit['_source']);
});
}

public function createIndex($name, array $options = [])
{
$params = [
'index' => $name,
];

if (isset($options['shards'])) {
$params['body']['settings']['number_of_shards'] = $options['shards'];
}

if (isset($options['replicas'])) {
$params['body']['settings']['number_of_replicas'] = $options['replicas'];
}

$this->elastic->indices()->create($params);
}

public function deleteIndex($name)
{
$this->elastic->indices()->delete(['index' => $name]);
}

/**
* Update the given model in the index.
*
Expand Down

0 comments on commit 9e6300e

Please sign in to comment.