Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit b57a9fc

Browse files
committed
Fixed the select method
1 parent a814033 commit b57a9fc

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/ElasticEngine.php

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,21 @@ protected function performSearch(Builder $builder, array $options = []) {
139139
);
140140
}
141141

142-
$result = null;
142+
$results = null;
143143

144-
$this->buildSearchQueryPayloadCollection($builder, $options)->each(function($payload) use (&$result) {
145-
$result = ElasticClient::search($payload);
144+
$this
145+
->buildSearchQueryPayloadCollection($builder, $options)
146+
->each(function($payload) use (&$results) {
147+
$results = ElasticClient::search($payload);
146148

147-
if ($this->getTotalCount($result) > 0) {
148-
return false;
149-
}
150-
});
149+
$results['_payload'] = $payload;
150+
151+
if ($this->getTotalCount($results) > 0) {
152+
return false;
153+
}
154+
});
151155

152-
return $result;
156+
return $results;
153157
}
154158

155159
public function search(Builder $builder)
@@ -226,15 +230,15 @@ public function map($results, $model)
226230
return Collection::make();
227231
}
228232

229-
$hits = $results['hits']['hits'];
230-
$firstHit = reset($hits);
231-
232233
$primaryKey = $model->getKeyName();
233234

234-
$columns = array_merge(
235-
array_keys($firstHit['_source']),
236-
[$primaryKey]
237-
);
235+
$columns = array_get($results, '_payload.body._source');
236+
237+
if (is_null($columns)) {
238+
$columns = ['*'];
239+
} else {
240+
$columns[] = $primaryKey;
241+
}
238242

239243
$ids = $this->mapIds($results);
240244

@@ -243,13 +247,16 @@ public function map($results, $model)
243247
->get($columns)
244248
->keyBy($primaryKey);
245249

246-
return Collection::make($hits)->map(function($hit) use ($models) {
247-
$id = $hit['_id'];
250+
return Collection::make($results['hits']['hits'])
251+
->map(function($hit) use ($models) {
252+
$id = $hit['_id'];
248253

249-
if (isset($models[$id])) {
250-
return $models[$id];
251-
}
252-
})->filter()->values();
254+
if (isset($models[$id])) {
255+
return $models[$id];
256+
}
257+
})
258+
->filter()
259+
->values();
253260
}
254261

255262
public function getTotalCount($results)

0 commit comments

Comments
 (0)