@@ -21,7 +21,7 @@ public function __construct(
2121 /**
2222 * Get the index name for the hit.
2323 */
24- public function indexName (): string
24+ public function index (): string
2525 {
2626 return $ this ->hit ['_index ' ];
2727 }
@@ -34,24 +34,82 @@ public function score(): ?float
3434 return $ this ->hit ['_score ' ];
3535 }
3636
37+ /**
38+ * Get the document identifier for the hit.
39+ */
40+ public function id (): string
41+ {
42+ return $ this ->hit ['_id ' ];
43+ }
44+
45+ /**
46+ * Get the document source for the hit.
47+ *
48+ * @return array<string, mixed>
49+ */
50+ public function source (): array
51+ {
52+ return $ this ->hit ['_source ' ] ?? [];
53+ }
54+
3755 /**
3856 * Get the document for the hit.
3957 */
4058 public function document (): Document
4159 {
42- return new Document (
43- $ this ->hit ['_id ' ],
44- $ this ->hit ['_source ' ] ?? []
45- );
60+ return new Document ($ this ->id (), $ this ->source ());
61+ }
62+
63+ /**
64+ * Get the returned document fields.
65+ *
66+ * @return array<string, mixed>
67+ */
68+ public function fields (): array
69+ {
70+ return $ this ->hit ['fields ' ] ?? [];
71+ }
72+
73+ /**
74+ * Get the hit sort values.
75+ *
76+ * @return array<int, mixed>
77+ */
78+ public function sort (): array
79+ {
80+ return $ this ->hit ['sort ' ] ?? [];
81+ }
82+
83+ /**
84+ * Get the matched query names.
85+ *
86+ * @return array<int, string>
87+ */
88+ public function matchedQueries (): array
89+ {
90+ return $ this ->hit ['matched_queries ' ] ?? [];
91+ }
92+
93+ /**
94+ * Get the score explanation.
95+ *
96+ * @return array<string, mixed>|null
97+ */
98+ public function explanation (): ?array
99+ {
100+ return $ this ->hit ['_explanation ' ] ?? null ;
46101 }
47102
48103 /**
49104 * Get the highlight for the hit.
50105 */
51106 public function highlight (): ?Highlight
52107 {
53- return isset ($ this ->hit ['highlight ' ]) ?
54- new Highlight ($ this ->hit ['highlight ' ]) : null ;
108+ if (isset ($ this ->hit ['highlight ' ])) {
109+ return new Highlight ($ this ->hit ['highlight ' ]);
110+ }
111+
112+ return null ;
55113 }
56114
57115 /**
@@ -61,15 +119,10 @@ public function highlight(): ?Highlight
61119 */
62120 public function innerHits (): array
63121 {
64- $ innerHits = $ this ->hit ['inner_hits ' ] ?? [];
65-
66- return array_map (
67- static fn (array $ hits ) => array_map (
68- static fn (array $ hit ) => new self ($ hit ),
69- $ hits ['hits ' ]['hits ' ],
70- ),
71- $ innerHits ,
72- );
122+ return array_map (fn (array $ hits ) => array_map (
123+ fn (array $ hit ) => new self ($ hit ),
124+ $ hits ['hits ' ]['hits ' ],
125+ ), $ this ->hit ['inner_hits ' ] ?? []);
73126 }
74127
75128 /**
0 commit comments