From 4462dcc3c42bc2d2bd24ad336c686183d0295db4 Mon Sep 17 00:00:00 2001 From: Will Taylor-Jackson Date: Fri, 12 Jan 2018 09:59:36 +0000 Subject: [PATCH 1/2] fix: remove vars from trait --- src/DesignMyNight/Elasticsearch/Searchable.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/DesignMyNight/Elasticsearch/Searchable.php b/src/DesignMyNight/Elasticsearch/Searchable.php index 2fd5144..4f8a63a 100644 --- a/src/DesignMyNight/Elasticsearch/Searchable.php +++ b/src/DesignMyNight/Elasticsearch/Searchable.php @@ -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 * From f94d87699b89891645b43201869b06f1706f64f9 Mon Sep 17 00:00:00 2001 From: Will Taylor-Jackson Date: Fri, 12 Jan 2018 09:59:50 +0000 Subject: [PATCH 2/2] feat: add collection with support for bulk indexing --- .../Elasticsearch/Collection.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/DesignMyNight/Elasticsearch/Collection.php diff --git a/src/DesignMyNight/Elasticsearch/Collection.php b/src/DesignMyNight/Elasticsearch/Collection.php new file mode 100644 index 0000000..8cb314f --- /dev/null +++ b/src/DesignMyNight/Elasticsearch/Collection.php @@ -0,0 +1,27 @@ +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); + } +} \ No newline at end of file