aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2017-04-01 22:31:12 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2017-04-01 22:31:12 +0200
commitd9c0d25b85ef3df7ea2cdc261e274efcdd5cfce0 (patch)
tree6db6cd1a2cca013ab6cc7809ce8ec9fad3e67b73 /app
parentf98cd52a02eb1e2d17b46ef9fddf327b0ebd55e2 (diff)
Improve search: intitle, author, inurl
Allow multiple values of intitle: , author:, inurl: Note: Tests for UserQueryTest are broken due to https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.0.0#backwards-compatibility-issues
Diffstat (limited to 'app')
-rw-r--r--app/Models/EntryDAO.php21
-rw-r--r--app/Models/Search.php60
2 files changed, 50 insertions, 31 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 61ec48d08..510755a2f 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -631,16 +631,22 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
if ($filter) {
if ($filter->getIntitle()) {
- $search .= 'AND ' . $alias . 'title LIKE ? ';
- $values[] = "%{$filter->getIntitle()}%";
+ foreach ($filter->getIntitle() as $title) {
+ $search .= 'AND ' . $alias . 'title LIKE ? ';
+ $values[] = "%{$title}%";
+ }
}
if ($filter->getInurl()) {
- $search .= 'AND CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ? ';
- $values[] = "%{$filter->getInurl()}%";
+ foreach ($filter->getInurl() as $url) {
+ $search .= 'AND CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ? ';
+ $values[] = "%{$url}%";
+ }
}
if ($filter->getAuthor()) {
- $search .= 'AND ' . $alias . 'author LIKE ? ';
- $values[] = "%{$filter->getAuthor()}%";
+ foreach ($filter->getAuthor() as $author) {
+ $search .= 'AND ' . $alias . 'author LIKE ? ';
+ $values[] = "%{$author}%";
+ }
}
if ($filter->getMinDate()) {
$search .= 'AND ' . $alias . 'id >= ? ';
@@ -659,8 +665,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$values[] = $filter->getMaxPubdate();
}
if ($filter->getTags()) {
- $tags = $filter->getTags();
- foreach ($tags as $tag) {
+ foreach ($filter->getTags() as $tag) {
$search .= 'AND ' . $alias . 'tags LIKE ? ';
$values[] = "%{$tag}%";
}
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 575a9a2cb..7b801f40b 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -81,6 +81,10 @@ class FreshRSS_Search {
return $this->search;
}
+ private static function removeEmptyValues($anArray) {
+ return is_array($anArray) ? array_filter($anArray, function($value) { return $value !== ''; }) : array();
+ }
+
/**
* Parse the search string to find intitle keyword and the search related
* to it.
@@ -90,14 +94,15 @@ class FreshRSS_Search {
* @return string
*/
private function parseIntitleSearch($input) {
- if (preg_match('/intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
+ if (preg_match_all('/intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->intitle = $matches['search'];
- return str_replace($matches[0], '', $input);
+ $input = str_replace($matches[0], '', $input);
}
- if (preg_match('/intitle:(?P<search>\w*)/', $input, $matches)) {
- $this->intitle = $matches['search'];
- return str_replace($matches[0], '', $input);
+ if (preg_match_all('/intitle:(?P<search>\w*)/', $input, $matches)) {
+ $this->intitle = array_merge($this->intitle ? $this->intitle : array(), $matches['search']);
+ $input = str_replace($matches[0], '', $input);
}
+ $this->intitle = self::removeEmptyValues($this->intitle);
return $input;
}
@@ -112,30 +117,32 @@ class FreshRSS_Search {
* @return string
*/
private function parseAuthorSearch($input) {
- if (preg_match('/author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
+ if (preg_match_all('/author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->author = $matches['search'];
- return str_replace($matches[0], '', $input);
+ $input = str_replace($matches[0], '', $input);
}
- if (preg_match('/author:(?P<search>\w*)/', $input, $matches)) {
- $this->author = $matches['search'];
- return str_replace($matches[0], '', $input);
+ if (preg_match_all('/author:(?P<search>\w*)/', $input, $matches)) {
+ $this->author = array_merge($this->author ? $this->author : array(), $matches['search']);
+ $input = str_replace($matches[0], '', $input);
}
+ $this->author = self::removeEmptyValues($this->author);
return $input;
}
/**
* Parse the search string to find inurl keyword and the search related
* to it.
- * The search is the first word following the keyword except.
+ * The search is the first word following the keyword.
*
* @param string $input
* @return string
*/
private function parseInurlSearch($input) {
- if (preg_match('/inurl:(?P<search>[^\s]*)/', $input, $matches)) {
+ if (preg_match_all('/inurl:(?P<search>[^\s]*)/', $input, $matches)) {
$this->inurl = $matches['search'];
- return str_replace($matches[0], '', $input);
+ $input = str_replace($matches[0], '', $input);
}
+ $this->inurl = self::removeEmptyValues($this->inurl);
return $input;
}
@@ -148,9 +155,12 @@ class FreshRSS_Search {
* @return string
*/
private function parseDateSearch($input) {
- if (preg_match('/date:(?P<search>[^\s]*)/', $input, $matches)) {
- list($this->min_date, $this->max_date) = parseDateInterval($matches['search']);
- return str_replace($matches[0], '', $input);
+ if (preg_match_all('/date:(?P<search>[^\s]*)/', $input, $matches)) {
+ $input = str_replace($matches[0], '', $input);
+ $dates = self::removeEmptyValues($matches['search']);
+ if (!empty($dates[0])) {
+ list($this->min_date, $this->max_date) = parseDateInterval($dates[0]);
+ }
}
return $input;
}
@@ -164,9 +174,12 @@ class FreshRSS_Search {
* @return string
*/
private function parsePubdateSearch($input) {
- if (preg_match('/pubdate:(?P<search>[^\s]*)/', $input, $matches)) {
- list($this->min_pubdate, $this->max_pubdate) = parseDateInterval($matches['search']);
- return str_replace($matches[0], '', $input);
+ if (preg_match_all('/pubdate:(?P<search>[^\s]*)/', $input, $matches)) {
+ $input = str_replace($matches[0], '', $input);
+ $dates = self::removeEmptyValues($matches['search']);
+ if (!empty($dates[0])) {
+ list($this->min_pubdate, $this->max_pubdate) = parseDateInterval($dates[0]);
+ }
}
return $input;
}
@@ -182,8 +195,9 @@ class FreshRSS_Search {
private function parseTagsSeach($input) {
if (preg_match_all('/#(?P<search>[^\s]+)/', $input, $matches)) {
$this->tags = $matches['search'];
- return str_replace($matches[0], '', $input);
+ $input = str_replace($matches[0], '', $input);
}
+ $this->tags = self::removeEmptyValues($this->tags);
return $input;
}
@@ -196,7 +210,7 @@ class FreshRSS_Search {
* @return string
*/
private function parseSearch($input) {
- $input = $this->cleanSearch($input);
+ $input = self::cleanSearch($input);
if (strcmp($input, '') == 0) {
return;
}
@@ -204,7 +218,7 @@ class FreshRSS_Search {
$this->search = $matches['search'];
$input = str_replace($matches[0], '', $input);
}
- $input = $this->cleanSearch($input);
+ $input = self::cleanSearch($input);
if (strcmp($input, '') == 0) {
return;
}
@@ -221,7 +235,7 @@ class FreshRSS_Search {
* @param string $input
* @return string
*/
- private function cleanSearch($input) {
+ private static function cleanSearch($input) {
$input = preg_replace('/\s+/', ' ', $input);
return trim($input);
}