From 2ffc8cf758dac6370d82371614f804932e3fda89 Mon Sep 17 00:00:00 2001 From: eqxdev Date: Fri, 24 Apr 2020 11:47:49 +0100 Subject: [PATCH 1/2] Adds the ability to add data into the body of each request set in the Seachable model --- src/ElasticEngine.php | 6 ++++++ src/Searchable.php | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/ElasticEngine.php b/src/ElasticEngine.php index 3e0e084..819a0da 100755 --- a/src/ElasticEngine.php +++ b/src/ElasticEngine.php @@ -153,6 +153,12 @@ public function buildSearchQueryPayloadCollection(Builder $builder, array $optio $payload->setIfNotEmpty($clauseKey, $clauseValue); } + $settings = $builder->model->getSearchSettings(); + foreach ($settings as $setting => $value) { + $settingKey = 'body.'.$setting; + $payload->setIfNotEmpty($settingKey, $value); + } + return $payload->get(); }); } diff --git a/src/Searchable.php b/src/Searchable.php index bd5da47..4d310b8 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -73,6 +73,17 @@ public function getSearchRules() $this->searchRules : [SearchRule::class]; } + /** + * Get the search rules. + * + * @return array + */ + public function getSearchSettings() + { + return isset($this->searchSettings) && count($this->searchSettings) > 0 ? + $this->searchSettings : array(); + } + /** * Execute the search. * From ec639d5c3dc78dffaee30b57e9f0b5030202b81c Mon Sep 17 00:00:00 2001 From: eqxdev Date: Fri, 24 Apr 2020 11:52:43 +0100 Subject: [PATCH 2/2] Make array meet the criteria --- src/Searchable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Searchable.php b/src/Searchable.php index 4d310b8..8bccc1c 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -81,7 +81,7 @@ public function getSearchRules() public function getSearchSettings() { return isset($this->searchSettings) && count($this->searchSettings) > 0 ? - $this->searchSettings : array(); + $this->searchSettings : []; } /**