-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add collection with support for bulk indexing
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |