Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to specify source fields to return for a search. #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class Search
*/
private $source;

/**
* Allows to selectively load specific source fields for each document represented by a search hit.
*
* @var array
*/
private $sourceFields;

/**
* Allows to selectively load specific stored fields for each document represented by a search hit.
*
Expand Down Expand Up @@ -537,6 +544,26 @@ public function setSource($source)
return $this;
}

/**
* @return array
*/
public function getSourceFields()
{
return $this->sourceFields;
}

/**
* @param array $sourceFields
*
* @return $this
*/
public function setSourceFields($sourceFields)
{
$this->sourceFields = $sourceFields;

return $this;
}

/**
* @return array
*/
Expand Down Expand Up @@ -793,6 +820,12 @@ public function toArray()
'trackTotalHits' => 'track_total_hits',
];

if(!empty($this->sourceFields))
{
unset($params['source']);
$params['sourceFields'] = '_source';
}

foreach ($params as $field => $param) {
if ($this->$field !== null) {
$output[$param] = $this->$field;
Expand Down