summaryrefslogtreecommitdiff
path: root/app/Models/Search.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <github@ainw.org> 2015-04-22 00:24:22 -0400
committerGravatar Alexis Degrugillier <github@ainw.org> 2015-04-22 00:24:22 -0400
commitd229216cccbd746b46630a44fa508ef0367ea1a1 (patch)
tree2f1cb423946abb94c9ad637ef8100328657b76ce /app/Models/Search.php
parent2a0d04dd0ec7f7a453cf15ef7846bca662335050 (diff)
Split the search into values
Before, the search was a single value. Now it is splited in chuncks when separated by spaces. Except if they are enclosed by single quotes or double quotes. For some reasons, the unit tests are working for both single and double quotes but the search box isn't. It is working only with single quotes. We need to investigate the reason of this behavior. See #823
Diffstat (limited to 'app/Models/Search.php')
-rw-r--r--app/Models/Search.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 84688be2e..575a9a2cb 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -34,9 +34,9 @@ class FreshRSS_Search {
$input = $this->parsePubdateSearch($input);
$input = $this->parseDateSearch($input);
$input = $this->parseTagsSeach($input);
- $this->search = $this->cleanSearch($input);
+ $this->parseSearch($input);
}
-
+
public function __toString() {
return $this->getRawInput();
}
@@ -188,6 +188,34 @@ class FreshRSS_Search {
}
/**
+ * Parse the search string to find search values.
+ * Every word is a distinct search value, except when using a delimiter.
+ * Supported delimiters are single quote (') and double quotes (").
+ *
+ * @param string $input
+ * @return string
+ */
+ private function parseSearch($input) {
+ $input = $this->cleanSearch($input);
+ if (strcmp($input, '') == 0) {
+ return;
+ }
+ if (preg_match_all('/(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
+ $this->search = $matches['search'];
+ $input = str_replace($matches[0], '', $input);
+ }
+ $input = $this->cleanSearch($input);
+ if (strcmp($input, '') == 0) {
+ return;
+ }
+ if (is_array($this->search)) {
+ $this->search = array_merge($this->search, explode(' ', $input));
+ } else {
+ $this->search = explode(' ', $input);
+ }
+ }
+
+ /**
* Remove all unnecessary spaces in the search
*
* @param string $input