Skip to content

Commit

Permalink
limit field with in:
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jun 13, 2018
1 parent 9ebf950 commit bdef408
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion lib/Model/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class SearchRequest implements \JsonSerializable {
/** @var array */
private $fields = [];

/** @var array */
private $limitFields = [];

/** @var array */
private $wildcardFields = [];

Expand Down Expand Up @@ -157,14 +160,21 @@ private function searchQueryOptions($word) {
}

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;
}

Expand Down Expand Up @@ -229,6 +239,22 @@ public function addOption($key, $value) {
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
*
Expand Down Expand Up @@ -280,6 +306,26 @@ public function setFields($fields) {
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
*
Expand Down

0 comments on commit bdef408

Please sign in to comment.