diff options
Diffstat (limited to 'lib/Model/SearchRequest.php')
-rw-r--r-- | lib/Model/SearchRequest.php | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index 35d1bbb..2a9013a 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -122,8 +122,44 @@ class SearchRequest implements \JsonSerializable { $this->search = $search; } + public function cleanSearch() { - $this->search = trim(str_replace(' ', ' ', $this->search)); + $search = trim(str_replace(' ', ' ', $this->getSearch())); + + preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words); + $searchItems = []; + foreach ($words[0] as $word) { + if ($this->searchQueryOptions($word)) { + continue; + } + + $searchItems[] = $word; + } + + $this->setSearch(implode(" ", $searchItems)); + } + + + /** + * @param $word + * + * @return bool + */ + private function searchQueryOptions($word) { + if (($pos = strpos($word, ':')) === false) { + return false; + } + + list($kw, $value) = explode(':', $word, 2); + $options = ['is', 'show']; + + if (in_array($kw, $options)) { + $this->addOption($kw . '_' . $value, '1'); + + return true; + } + + return false; } @@ -176,6 +212,18 @@ class SearchRequest implements \JsonSerializable { } /** + * @param $key + * @param $value + * + * @return $this + */ + public function addOption($key, $value) { + $this->options[$key] = $value; + + return $this; + } + + /** * @param string $option * * @return mixed|string |