Skip to content

Commit 6944399

Browse files
author
Lindsay Snider
committed
applying PR ongr-io#358
1 parent b4c3c89 commit 6944399

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: src/Search.php

+33
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class Search
6767
*/
6868
private $source;
6969

70+
/**
71+
* Allows to selectively load specific source fields for each document represented by a search hit.
72+
*
73+
* @var array
74+
*/
75+
private $sourceFields;
76+
7077
/**
7178
* Allows to selectively load specific stored fields for each document represented by a search hit.
7279
*
@@ -537,6 +544,26 @@ public function setSource($source)
537544
return $this;
538545
}
539546

547+
/**
548+
* @return array
549+
*/
550+
public function getSourceFields()
551+
{
552+
return $this->sourceFields;
553+
}
554+
555+
/**
556+
* @param array $sourceFields
557+
*
558+
* @return $this
559+
*/
560+
public function setSourceFields($sourceFields)
561+
{
562+
$this->sourceFields = $sourceFields;
563+
564+
return $this;
565+
}
566+
540567
/**
541568
* @return array
542569
*/
@@ -793,6 +820,12 @@ public function toArray()
793820
'trackTotalHits' => 'track_total_hits',
794821
];
795822

823+
if(!empty($this->sourceFields))
824+
{
825+
unset($params['source']);
826+
$params['sourceFields'] = '_source';
827+
}
828+
796829
foreach ($params as $field => $param) {
797830
if ($this->$field !== null) {
798831
$output[$param] = $this->$field;

0 commit comments

Comments
 (0)