diff --git a/composer.json b/composer.json index ad7d337..5f75413 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/Engines/ElasticsearchEngine.php b/src/Engines/ElasticsearchEngine.php index dfc2b8d..1603b45 100644 --- a/src/Engines/ElasticsearchEngine.php +++ b/src/Engines/ElasticsearchEngine.php @@ -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. *