-
Notifications
You must be signed in to change notification settings - Fork 732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #1906 - setOption('filter_path', 'responses.hits.hits._source'); #1907
base: 8.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||
namespace Elastica\Multi; | ||||||
|
||||||
use Elastica\Client; | ||||||
use Elastica\Exception\InvalidException; | ||||||
use Elastica\JSON; | ||||||
use Elastica\Request; | ||||||
use Elastica\Search as BaseSearch; | ||||||
|
@@ -54,6 +55,113 @@ public function __construct(Client $client, ?MultiBuilderInterface $builder = nu | |||||
$this->_builder = $builder ?? new MultiBuilder(); | ||||||
$this->_client = $client; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param string $key | ||||||
* @param mixed $value | ||||||
* | ||||||
* @return $this | ||||||
*/ | ||||||
public function setOption($key, $value) | ||||||
{ | ||||||
$this->_validateOption($key); | ||||||
|
||||||
$this->_options[$key] = $value; | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param array $options | ||||||
* | ||||||
* @return $this | ||||||
*/ | ||||||
public function setOptions(array $options) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
$this->clearOptions(); | ||||||
|
||||||
foreach ($options as $key => $value) { | ||||||
$this->setOption($key, $value); | ||||||
} | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return $this | ||||||
*/ | ||||||
public function clearOptions() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
$this->_options = []; | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param string $key | ||||||
* @param mixed $value | ||||||
* | ||||||
* @return $this | ||||||
*/ | ||||||
public function addOption($key, $value) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
$this->_validateOption($key); | ||||||
|
||||||
$this->_options[$key][] = $value; | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param string $key | ||||||
* | ||||||
* @return bool | ||||||
*/ | ||||||
public function hasOption($key) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return isset($this->_options[$key]); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param string $key | ||||||
* | ||||||
* @throws \Elastica\Exception\InvalidException | ||||||
* | ||||||
* @return mixed | ||||||
*/ | ||||||
public function getOption($key) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
if (!$this->hasOption($key)) { | ||||||
throw new InvalidException('Option '.$key.' does not exist'); | ||||||
} | ||||||
|
||||||
return $this->_options[$key]; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return array | ||||||
*/ | ||||||
public function getOptions() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->_options; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param string $key | ||||||
* | ||||||
* @throws \Elastica\Exception\InvalidException | ||||||
* | ||||||
* @return bool | ||||||
*/ | ||||||
protected function _validateOption($key) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
switch ($key) { | ||||||
case BaseSearch::OPTION_FILTER_PATH: | ||||||
return true; | ||||||
} | ||||||
|
||||||
throw new InvalidException('Invalid option '.$key); | ||||||
} | ||||||
|
||||||
public function getClient(): Client | ||||||
{ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument
$key
can probably be type-hinted