Skip to content

Commit

Permalink
Merge pull request #15 from designmynight/add-collection
Browse files Browse the repository at this point in the history
Add collection
  • Loading branch information
Will Taylor-Jackson authored Jan 12, 2018
2 parents 52ec3de + f94d876 commit 345d1e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 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);
}
}
18 changes: 0 additions & 18 deletions src/DesignMyNight/Elasticsearch/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@
namespace DesignMyNight\Elasticsearch;

trait Searchable {
/**
* The Elasticsearch index this model should be added to
* @var string
*/
protected $searchIndex;

/**
* The type of document this should be added as
* @var string
*/
protected $searchType;

/**
* A list of embedded fields that should be indexed as child documents
* @var array
*/
protected $indexAsChildDocuments;

/**
* Get the index this model is to be added to
*
Expand Down

0 comments on commit 345d1e1

Please sign in to comment.