Skip to content

Commit

Permalink
Add request_cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
babenkoivan committed Mar 28, 2023
1 parent 5003deb commit 949ca4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ $searchParameters->explain(true);
// set maximum number of documents to collect for each shard
$searchParameters->terminateAfter(10);

// enable caching
$searchParameters->requestCache(true);

// perform the search and get the result
$searchResult = $documentManager->search($searchParameters);

Expand Down
6 changes: 6 additions & 0 deletions src/Search/SearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public function terminateAfter(int $terminateAfter): self
return $this;
}

public function requestCache(bool $requestCache): self
{
$this->params['request_cache'] = $requestCache;
return $this;
}

public function toArray(): array
{
return $this->params;
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/Search/SearchParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,10 @@ public function test_array_casting_with_terminate_after(): void
$searchParameters = (new SearchParameters())->terminateAfter(10);
$this->assertSame(['terminate_after' => 10], $searchParameters->toArray());
}

public function test_array_casting_with_request_cache(): void
{
$searchParameters = (new SearchParameters())->requestCache(true);
$this->assertSame(['request_cache' => true], $searchParameters->toArray());
}
}

0 comments on commit 949ca4a

Please sign in to comment.