Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ public static function create(

$page = (int) (max(1, $page));
$query = new static($queryText);
$query->from = ($page - 1) * $size;
$query->size = $size;
$query->page = $page;
$query->calculateFrom();

return $query;
}
Expand Down Expand Up @@ -338,6 +338,15 @@ public function getFields(): array
return $this->fields;
}

/**
* @param int $page
*/
public function forcePage(int $page): void
{
$this->page = $page;
$this->calculateFrom();
}

/**
* @param int $size
*
Expand All @@ -346,6 +355,15 @@ public function getFields(): array
public function forceSize(int $size)
{
$this->size = $size;
$this->calculateFrom();
}

/**
* @return void
*/
public function calculateFrom()
{
$this->from = ($this->page - 1) * $this->size;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion Tests/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,22 @@ public function testDeleteAggregationByField()
$this->assertNull($query->getAggregation('field3'));
}

public function testForceSize()
public function testForceSizeAndPage()
{
$query = Query::create('x', 1, 10);
$this->assertEquals(10, $query->getSize());
$this->assertEquals(0, $query->getFrom());
$query->forceSize(7);
$this->assertEquals(7, $query->getSize());
$this->assertEquals(0, $query->getFrom());

$query = Query::create('x', 2, 5);
$this->assertEquals(2, $query->getPage());
$this->assertEquals(5, $query->getSize());
$this->assertEquals(5, $query->getFrom());

$query->forcePage(3);
$this->assertEquals(3, $query->getPage());
$this->assertEquals(10, $query->getFrom());
}
}