Skip to content

Commit

Permalink
feat: add collection with support for bulk indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Taylor-Jackson committed Jan 12, 2018
1 parent 4462dcc commit f94d876
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/DesignMyNight/Elasticsearch/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace DesignMyNight\Elasticsearch;

use Illuminate\Support\Collection as BaseCollection;

class Collection extends BaseCollection
{
public function addToIndex()
{
if ( $this->isEmpty() ){
return;
}

$instance = $this->first();

$docs = $this->map(function($model){
return $model->toSearchableArray();
});

return $instance->onSearchConnection(function($docs, $instance){
$query = $instance->newQueryWithoutScopes();

return $query->insert($docs->all());
}, $docs, $instance);
}
}

0 comments on commit f94d876

Please sign in to comment.