From 04aaa86da0f4c474eb2e4fde3661e76ec63ddff7 Mon Sep 17 00:00:00 2001 From: "Exploit.cz" Date: Wed, 3 Mar 2021 08:04:59 +0100 Subject: [PATCH] Update Search.php $search->setOption('filter_path', 'responses.hits.hits._source'); --- src/Multi/Search.php | 108 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/src/Multi/Search.php b/src/Multi/Search.php index 851141eac7..d9a2ce984c 100644 --- a/src/Multi/Search.php +++ b/src/Multi/Search.php @@ -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) + { + $this->clearOptions(); + + foreach ($options as $key => $value) { + $this->setOption($key, $value); + } + + return $this; + } + + /** + * @return $this + */ + public function clearOptions() + { + $this->_options = []; + + return $this; + } + + /** + * @param string $key + * @param mixed $value + * + * @return $this + */ + public function addOption($key, $value) + { + $this->_validateOption($key); + + $this->_options[$key][] = $value; + + return $this; + } + + /** + * @param string $key + * + * @return bool + */ + public function hasOption($key) + { + return isset($this->_options[$key]); + } + + /** + * @param string $key + * + * @throws \Elastica\Exception\InvalidException + * + * @return mixed + */ + public function getOption($key) + { + if (!$this->hasOption($key)) { + throw new InvalidException('Option '.$key.' does not exist'); + } + + return $this->_options[$key]; + } + + /** + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * @param string $key + * + * @throws \Elastica\Exception\InvalidException + * + * @return bool + */ + protected function _validateOption($key) + { + switch ($key) { + case BaseSearch::OPTION_FILTER_PATH: + return true; + } + + throw new InvalidException('Invalid option '.$key); + } public function getClient(): Client {