File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -243,9 +243,9 @@ public static function create(
243
243
244
244
$ page = (int ) (max (1 , $ page ));
245
245
$ query = new static ($ queryText );
246
- $ query ->from = ($ page - 1 ) * $ size ;
247
246
$ query ->size = $ size ;
248
247
$ query ->page = $ page ;
248
+ $ query ->calculateFrom ();
249
249
250
250
return $ query ;
251
251
}
@@ -338,6 +338,15 @@ public function getFields(): array
338
338
return $ this ->fields ;
339
339
}
340
340
341
+ /**
342
+ * @param int $page
343
+ */
344
+ public function forcePage (int $ page ): void
345
+ {
346
+ $ this ->page = $ page ;
347
+ $ this ->calculateFrom ();
348
+ }
349
+
341
350
/**
342
351
* @param int $size
343
352
*
@@ -346,6 +355,15 @@ public function getFields(): array
346
355
public function forceSize (int $ size )
347
356
{
348
357
$ this ->size = $ size ;
358
+ $ this ->calculateFrom ();
359
+ }
360
+
361
+ /**
362
+ * @return void
363
+ */
364
+ public function calculateFrom ()
365
+ {
366
+ $ this ->from = ($ this ->page - 1 ) * $ this ->size ;
349
367
}
350
368
351
369
/**
Original file line number Diff line number Diff line change @@ -367,11 +367,22 @@ public function testDeleteAggregationByField()
367
367
$ this ->assertNull ($ query ->getAggregation ('field3 ' ));
368
368
}
369
369
370
- public function testForceSize ()
370
+ public function testForceSizeAndPage ()
371
371
{
372
372
$ query = Query::create ('x ' , 1 , 10 );
373
373
$ this ->assertEquals (10 , $ query ->getSize ());
374
+ $ this ->assertEquals (0 , $ query ->getFrom ());
374
375
$ query ->forceSize (7 );
375
376
$ this ->assertEquals (7 , $ query ->getSize ());
377
+ $ this ->assertEquals (0 , $ query ->getFrom ());
378
+
379
+ $ query = Query::create ('x ' , 2 , 5 );
380
+ $ this ->assertEquals (2 , $ query ->getPage ());
381
+ $ this ->assertEquals (5 , $ query ->getSize ());
382
+ $ this ->assertEquals (5 , $ query ->getFrom ());
383
+
384
+ $ query ->forcePage (3 );
385
+ $ this ->assertEquals (3 , $ query ->getPage ());
386
+ $ this ->assertEquals (10 , $ query ->getFrom ());
376
387
}
377
388
}
You can’t perform that action at this time.
0 commit comments