Skip to content

Commit

Permalink
Removed 3rd $method argument from the `Elastica\SearchableInterface…
Browse files Browse the repository at this point in the history
…::search` and `Elastica\SearchableInterface::count` as they are not unused anymore. Removed Request class
  • Loading branch information
sidz committed Jan 12, 2025
1 parent 6d122c6 commit df87b52
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/ruflin/Elastica/compare/8.1.0...8.x)

### Backward Compatibility Breaks
* Removed 3rd `$method` argument from the `Elastica\SearchableInterface::search` and `Elastica\SearchableInterface::count` as they are not unused anymore. The following classes are affected: `Elastica\Search` and `Elastica\Index`
* Removed `Elastica\Request` class as constants are not used anymore and no longer needed.

### Added
### Changed
### Deprecated
Expand Down
8 changes: 4 additions & 4 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,18 @@ public function createSearch($query = '', ?array $options = null, ?BuilderInterf
return $search;
}

public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet
public function search($query = '', ?array $options = null): ResultSet
{
$search = $this->createSearch($query, $options);

return $search->search('', null, $method);
return $search->search('', null);
}

public function count($query = '', string $method = Request::POST): int
public function count($query = ''): int
{
$search = $this->createSearch($query);

return $search->count('', false, $method);
return $search->count('', false);
}

/**
Expand Down
21 changes: 0 additions & 21 deletions src/Request.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function getPath(): string
* @throws ServerResponseException if the status code of response is 5xx
* @throws ClientException
*/
public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet
public function search($query = '', ?array $options = null): ResultSet
{
$this->setOptionsAndQuery($options, $query);

Expand Down Expand Up @@ -323,7 +323,7 @@ public function search($query = '', ?array $options = null, string $method = Req
*
* @phpstan-return ($fullResult is false ? int : ResultSet)
*/
public function count($query = '', bool $fullResult = false, string $method = Request::POST)
public function count($query = '', bool $fullResult = false)
{
$this->setOptionsAndQuery(null, $query);

Expand Down
7 changes: 2 additions & 5 deletions src/SearchableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ interface SearchableInterface
* @phpstan-param TCreateQueryArgs $query
*
* @param array<string, mixed>|null $options associative array of options (option=>value)
* @param string $method Request method, see Request's constants
*
* @throws NoNodeAvailableException if all the hosts are offline
* @throws ClientResponseException if the status code of response is 4xx
* @throws ServerResponseException if the status code of response is 5xx
* @throws InvalidException
* @throws ClientException
*/
public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet;
public function search($query = '', ?array $options = null): ResultSet;

/**
* Counts results for a query.
Expand All @@ -62,16 +61,14 @@ public function search($query = '', ?array $options = null, string $method = Req
*
* @phpstan-param TCreateQueryArgsMatching $query
*
* @param string $method Request method, see Request's constants
*
* @throws NoNodeAvailableException if all the hosts are offline
* @throws ClientResponseException if the status code of response is 4xx
* @throws ServerResponseException if the status code of response is 5xx
* @throws ClientException
*
* @return int number of documents matching the query
*/
public function count($query = '', string $method = Request::POST);
public function count($query = '');

/**
* @param AbstractQuery|AbstractSuggest|array|Collapse|Query|string|Suggest|null $query
Expand Down
9 changes: 4 additions & 5 deletions tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Elastica\Query\QueryString;
use Elastica\Query\SimpleQueryString;
use Elastica\Query\Term;
use Elastica\Request;
use Elastica\Script\Script;
use Elastica\Status;
use Elastica\Test\Base as BaseTest;
Expand Down Expand Up @@ -165,14 +164,14 @@ public function testCountGet(): void

$index->refresh();

$this->assertEquals(2, $index->count('', Request::GET));
$this->assertEquals(2, $index->count(''));

$query = new Term();
$key = 'name';
$value = 'nicolas';
$query->setTerm($key, $value);

$this->assertEquals(1, $index->count($query, Request::GET));
$this->assertEquals(1, $index->count($query));
}

/**
Expand Down Expand Up @@ -794,10 +793,10 @@ public function testSearchGet(): void
$index->addDocuments($docs);
$index->refresh();

$resultSet = $index->search('hans', null, Request::GET);
$resultSet = $index->search('hans', null);
$this->assertEquals(1, $resultSet->count());

$count = $index->count('hans', Request::GET);
$count = $index->count('hans');
$this->assertEquals(1, $count);
}

Expand Down
13 changes: 6 additions & 7 deletions tests/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Elastica\Query\FunctionScore;
use Elastica\Query\MatchAll;
use Elastica\Query\QueryString;
use Elastica\Request;
use Elastica\ResultSet;
use Elastica\Script\Script;
use Elastica\Search;
Expand Down Expand Up @@ -478,7 +477,7 @@ public function testSearchGet(): void
$client = $this->_getClient();
$search1 = new Search($client);

$result = $search1->search([], [], 'GET');
$result = $search1->search([], []);
$this->assertFalse($result->getResponse()->hasError());
}

Expand Down Expand Up @@ -578,19 +577,19 @@ public function testCountRequestGet(): void

$search->addIndex($index);

$count = $search->count('farrelley', false, Request::GET);
$count = $search->count('farrelley', false);
$this->assertEquals(5, $count);

$count = $search->count('marley', false, Request::GET);
$count = $search->count('marley', false);
$this->assertEquals(6, $count);

$count = $search->count('', false, Request::GET);
$count = $search->count('', false);
$this->assertEquals(6, $count, 'Uses previous query set');

$count = $search->count(new MatchAll(), false, Request::GET);
$count = $search->count(new MatchAll(), false);
$this->assertEquals(11, $count);

$count = $search->count('bunny', false, Request::GET);
$count = $search->count('bunny', false);
$this->assertEquals(0, $count);
}

Expand Down

0 comments on commit df87b52

Please sign in to comment.