@@ -74,6 +74,11 @@ class Result implements HttpTransportable
74
74
*/
75
75
private $ subresults = [];
76
76
77
+ /**
78
+ * @var array
79
+ */
80
+ private $ metadata ;
81
+
77
82
/**
78
83
* Result constructor.
79
84
*
@@ -114,7 +119,8 @@ public static function create(
114
119
? Aggregations $ aggregations ,
115
120
array $ suggestions ,
116
121
array $ items ,
117
- ? string $ autocomplete = null
122
+ ? string $ autocomplete = null ,
123
+ array $ metadata = []
118
124
): self {
119
125
$ result = new self (
120
126
$ query ,
@@ -123,9 +129,10 @@ public static function create(
123
129
);
124
130
125
131
$ result ->aggregations = $ aggregations ;
126
- $ result ->suggestions = $ suggestions ;
132
+ $ result ->suggestions = array_combine ( $ suggestions, $ suggestions ) ;
127
133
$ result ->items = $ items ;
128
134
$ result ->autocomplete = $ autocomplete ;
135
+ $ result ->metadata = $ metadata ;
129
136
130
137
return $ result ;
131
138
}
@@ -382,6 +389,43 @@ public function getSubresults(): array
382
389
return $ this ->subresults ;
383
390
}
384
391
392
+ /**
393
+ * Set metadata.
394
+ *
395
+ * @param string $name
396
+ * @param mixed $value
397
+ *
398
+ * @return Query
399
+ */
400
+ public function setMetadataValue (
401
+ string $ name ,
402
+ $ value
403
+ ): self {
404
+ $ this ->metadata [$ name ] = $ value ;
405
+
406
+ return $ this ;
407
+ }
408
+
409
+ /**
410
+ * Get metadata.
411
+ *
412
+ * @return array
413
+ */
414
+ public function getMetadata (): array
415
+ {
416
+ return $ this ->metadata ;
417
+ }
418
+
419
+ /**
420
+ * Get metadata value.
421
+ *
422
+ * @return mixed|null
423
+ */
424
+ public function getMetadataValue (string $ name )
425
+ {
426
+ return $ this ->metadata [$ name ] ?? null ;
427
+ }
428
+
385
429
/**
386
430
* To array.
387
431
*
@@ -399,13 +443,14 @@ public function toArray(): array
399
443
'aggregations ' => $ this ->aggregations instanceof Aggregations
400
444
? $ this ->aggregations ->toArray ()
401
445
: null ,
402
- 'suggests ' => array_keys ($ this ->suggestions ),
446
+ 'suggests ' => array_values ($ this ->suggestions ),
403
447
'autocomplete ' => '' === $ this ->autocomplete
404
448
? null
405
449
: $ this ->autocomplete ,
406
450
'subresults ' => array_map (function (Result $ result ) {
407
451
return $ result ->toArray ();
408
452
}, $ this ->subresults ),
453
+ 'metadata ' => $ this ->metadata ,
409
454
], function ($ element ) {
410
455
return
411
456
!(
@@ -437,7 +482,8 @@ public static function createFromArray(array $array): self
437
482
array_map (function (array $ item ) {
438
483
return Item::createFromArray ($ item );
439
484
}, $ array ['items ' ] ?? []),
440
- $ array ['autocomplete ' ] ?? null
485
+ $ array ['autocomplete ' ] ?? null ,
486
+ $ array ['metadata ' ] ?? []
441
487
);
442
488
443
489
$ result ->queryUUID = $ array ['query_uuid ' ] ?? '' ;
0 commit comments