This repository was archived by the owner on Jun 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 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(
243243
244244 $ page = (int ) (max (1 , $ page ));
245245 $ query = new static ($ queryText );
246- $ query ->from = ($ page - 1 ) * $ size ;
247246 $ query ->size = $ size ;
248247 $ query ->page = $ page ;
248+ $ query ->calculateFrom ();
249249
250250 return $ query ;
251251 }
@@ -338,6 +338,15 @@ public function getFields(): array
338338 return $ this ->fields ;
339339 }
340340
341+ /**
342+ * @param int $page
343+ */
344+ public function forcePage (int $ page ): void
345+ {
346+ $ this ->page = $ page ;
347+ $ this ->calculateFrom ();
348+ }
349+
341350 /**
342351 * @param int $size
343352 *
@@ -346,6 +355,15 @@ public function getFields(): array
346355 public function forceSize (int $ size )
347356 {
348357 $ 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 ;
349367 }
350368
351369 /**
Original file line number Diff line number Diff line change @@ -367,11 +367,22 @@ public function testDeleteAggregationByField()
367367 $ this ->assertNull ($ query ->getAggregation ('field3 ' ));
368368 }
369369
370- public function testForceSize ()
370+ public function testForceSizeAndPage ()
371371 {
372372 $ query = Query::create ('x ' , 1 , 10 );
373373 $ this ->assertEquals (10 , $ query ->getSize ());
374+ $ this ->assertEquals (0 , $ query ->getFrom ());
374375 $ query ->forceSize (7 );
375376 $ 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 ());
376387 }
377388}
You can’t perform that action at this time.
0 commit comments