File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,13 @@ class Search
67
67
*/
68
68
private $ source ;
69
69
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
+
70
77
/**
71
78
* Allows to selectively load specific stored fields for each document represented by a search hit.
72
79
*
@@ -537,6 +544,26 @@ public function setSource($source)
537
544
return $ this ;
538
545
}
539
546
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
+
540
567
/**
541
568
* @return array
542
569
*/
@@ -793,6 +820,12 @@ public function toArray()
793
820
'trackTotalHits ' => 'track_total_hits ' ,
794
821
];
795
822
823
+ if (!empty ($ this ->sourceFields ))
824
+ {
825
+ unset($ params ['source ' ]);
826
+ $ params ['sourceFields ' ] = '_source ' ;
827
+ }
828
+
796
829
foreach ($ params as $ field => $ param ) {
797
830
if ($ this ->$ field !== null ) {
798
831
$ output [$ param ] = $ this ->$ field ;
You can’t perform that action at this time.
0 commit comments