Code Duplication    Length = 34-34 lines in 2 locations

tests/Query/FunctionScoreTest.php 2 locations

@@ 266-299 (lines=34) @@
263
    /**
264
     * @group functional
265
     */
266
    public function testRandomScore(): void
267
    {
268
        $filter = new Term(['price' => 4.5]);
269
        $query = new FunctionScore();
270
        $query->addRandomScoreFunction(2, $filter, null, '_id');
271
272
        $expected = [
273
            'function_score' => [
274
                'functions' => [
275
                    [
276
                        'random_score' => [
277
                            'seed' => 2,
278
                            'field' => '_id',
279
                        ],
280
                        'filter' => [
281
                            'term' => [
282
                                'price' => 4.5,
283
                            ],
284
                        ],
285
                    ],
286
                ],
287
            ],
288
        ];
289
290
        $this->assertEquals($expected, $query->toArray());
291
292
        $response = $this->_getIndexForTest()->search($query);
293
        $results = $response->getResults();
294
295
        // the document with the random score should have a score > 1, means it is the first result
296
        $result0 = $results[0]->getData();
297
298
        $this->assertEquals("Miller's Field", $result0['name']);
299
    }
300
301
    /**
302
     * @group functional
@@ 304-337 (lines=34) @@
301
    /**
302
     * @group functional
303
     */
304
    public function testRandomScoreWithLegacyFilter(): void
305
    {
306
        $filter = new Term(['price' => 4.5]);
307
        $query = new FunctionScore();
308
        $query->addRandomScoreFunction(2, $filter, null, '_id');
309
310
        $expected = [
311
            'function_score' => [
312
                'functions' => [
313
                    [
314
                        'random_score' => [
315
                            'seed' => 2,
316
                            'field' => '_id',
317
                        ],
318
                        'filter' => [
319
                            'term' => [
320
                                'price' => 4.5,
321
                            ],
322
                        ],
323
                    ],
324
                ],
325
            ],
326
        ];
327
328
        $this->assertEquals($expected, $query->toArray());
329
330
        $response = $this->_getIndexForTest()->search($query);
331
        $results = $response->getResults();
332
333
        // the document with the random score should have a score > 1, means it is the first result
334
        $result0 = $results[0]->getData();
335
336
        $this->assertEquals("Miller's Field", $result0['name']);
337
    }
338
339
    /**
340
     * @group unit