Skip to content

Commit

Permalink
Merge pull request #17 from designmynight/add-collection
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
Will Taylor-Jackson authored Jan 13, 2018
2 parents a204f34 + b495c92 commit f069b47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/DesignMyNight/Elasticsearch/EloquentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setModel(Model $model)
{
$this->model = $model;

$this->query->from($model->getTable());
$this->query->from($model->getSearchIndex());

$this->query->type($model->getSearchType());

Expand Down
10 changes: 7 additions & 3 deletions src/DesignMyNight/Elasticsearch/QueryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function processSelect(Builder $query, $results)

$this->aggregations = $results['aggregations'] ?? [];

$this->query = $query;

// Return a generator if we got a scroll cursor in the results
if (isset($results['_scroll_id'])){
return $this->yieldResults($results);
Expand All @@ -50,13 +52,13 @@ protected function yieldResults($results): Generator
{
// First yield each result from the initial request
foreach ($results['hits']['hits'] as $result){
yield $this->documentFromResult($query, $result);
yield $this->documentFromResult($this->query, $result);
}

// Then go through the scroll cursor getting one result at a time
if (isset($results['scrollCursor'])){
foreach ($results['scrollCursor'] as $result){
$document = $this->documentFromResult($query, $result);
$document = $this->documentFromResult($this->query, $result);

yield $document;
}
Expand Down Expand Up @@ -92,7 +94,9 @@ protected function documentFromResult(Builder $query, array $result): array
protected function addInnerHitsToDocument($document, $innerHits): array
{
foreach ($innerHits as $documentType => $hitResults){
$document['inner_hits'][$documentType] = array_column($hitResults['hits']['hits'], '_source');
foreach ( $hitResults['hits']['hits'] as $result ){
$document['inner_hits'][$documentType][] = array_merge(['_id' => $result['_id']], $result['_source']);
}
}

return $document;
Expand Down

0 comments on commit f069b47

Please sign in to comment.