From bdef408c1f6ddbef80827fae36aa933a036f819c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 13 Jun 2018 17:10:39 -0100 Subject: limit field with in: Signed-off-by: Maxence Lange --- lib/Model/SearchRequest.php | 48 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index eec7d32..5afb2db 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -57,6 +57,9 @@ class SearchRequest implements \JsonSerializable { /** @var array */ private $fields = []; + /** @var array */ + private $limitFields = []; + /** @var array */ private $wildcardFields = []; @@ -157,14 +160,21 @@ class SearchRequest implements \JsonSerializable { } list($kw, $value) = explode(':', $word, 2); - $options = ['is', 'show']; + $options = ['is', 'show']; if (in_array($kw, $options)) { $this->addOption($kw . '_' . $value, '1'); return true; } + $valuedOptions = ['in']; + if (in_array($kw, $valuedOptions)) { + $this->addMultipleOption($kw, $value); + + return true; + } + return false; } @@ -229,6 +239,22 @@ class SearchRequest implements \JsonSerializable { return $this; } + /** + * @param $key + * @param $value + * + * @return $this + */ + public function addMultipleOption($key, $value) { + if (!array_key_exists($key, $this->options)) { + $this->options[$key] = []; + } + + $this->options[$key][] = $value; + + return $this; + } + /** * @param string $option * @@ -280,6 +306,26 @@ class SearchRequest implements \JsonSerializable { return $this; } + + /** + * @param $field + * + * @return $this + */ + public function limitToField($field) { + array_push($this->limitFields, $field); + + return $this; + } + + /** + * @return array + */ + public function getLimitFields() { + return $this->limitFields; + } + + /** * @param $field * -- cgit v1.2.3