@@ -131,6 +131,72 @@ public function testSearchCondition(): void
131
131
}
132
132
}
133
133
134
+ public function testSearchConditionWithHighlight (): void
135
+ {
136
+ $ documents = TestingHelper::createComplexFixtures ();
137
+
138
+ $ schema = self ::getSchema ();
139
+
140
+ foreach ($ documents as $ document ) {
141
+ self ::$ taskHelper ->tasks [] = self ::$ indexer ->save (
142
+ $ schema ->indexes [TestingHelper::INDEX_COMPLEX ],
143
+ $ document ,
144
+ ['return_slow_promise_result ' => true ],
145
+ );
146
+ }
147
+ self ::$ taskHelper ->waitForAll ();
148
+
149
+ $ search = new SearchBuilder ($ schema , self ::$ searcher );
150
+ $ search ->index (TestingHelper::INDEX_COMPLEX );
151
+ $ search ->addFilter (new Condition \SearchCondition ('Blog ' ));
152
+ $ search ->highlight (['title ' ], '<mark> ' , '</mark> ' );
153
+
154
+ $ expectedDocumentA = $ documents [0 ];
155
+ $ expectedDocumentA ['_formatted ' ]['title ' ] = \str_replace (
156
+ 'Blog ' ,
157
+ '<mark>Blog</mark> ' ,
158
+ $ expectedDocumentA ['title ' ] ?? '' ,
159
+ );
160
+ $ expectedDocumentB = $ documents [1 ];
161
+ $ expectedDocumentB ['_formatted ' ]['title ' ] = \str_replace (
162
+ 'Blog ' ,
163
+ '<mark>Blog</mark> ' ,
164
+ $ expectedDocumentB ['title ' ] ?? '' ,
165
+ );
166
+
167
+ $ expectedDocumentsVariantA = [
168
+ $ expectedDocumentA ,
169
+ $ expectedDocumentB ,
170
+ ];
171
+ $ expectedDocumentsVariantB = [
172
+ $ expectedDocumentB ,
173
+ $ expectedDocumentA ,
174
+ ];
175
+
176
+ $ loadedDocuments = [...$ search ->getResult ()];
177
+ $ this ->assertCount (2 , $ loadedDocuments );
178
+
179
+ $ this ->assertTrue (
180
+ $ expectedDocumentsVariantA === $ loadedDocuments
181
+ || $ expectedDocumentsVariantB === $ loadedDocuments ,
182
+ 'Not correct documents where found. ' ,
183
+ );
184
+
185
+ $ search = new SearchBuilder ($ schema , self ::$ searcher );
186
+ $ search ->index (TestingHelper::INDEX_COMPLEX );
187
+ $ search ->addFilter (new Condition \SearchCondition ('Thing ' ));
188
+
189
+ $ this ->assertSame ([$ documents [2 ]], [...$ search ->getResult ()]);
190
+
191
+ foreach ($ documents as $ document ) {
192
+ self ::$ taskHelper ->tasks [] = self ::$ indexer ->delete (
193
+ $ schema ->indexes [TestingHelper::INDEX_COMPLEX ],
194
+ $ document ['uuid ' ],
195
+ ['return_slow_promise_result ' => true ],
196
+ );
197
+ }
198
+ }
199
+
134
200
public function testNoneSearchableFields (): void
135
201
{
136
202
$ documents = TestingHelper::createComplexFixtures ();
0 commit comments