aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2021-07-24 19:32:43 +0200
committerGravatar GitHub <noreply@github.com> 2021-07-24 19:32:43 +0200
commit705be9a6a1608ff195c0f24004d07cb8823fa6de (patch)
tree998bf3c93771e94fe470401d3b7a40a662e4e4d0 /app/Models/EntryDAO.php
parent247dfa6c1ba0f60b7cca63141c94d5754b2bd7e5 (diff)
Search labels (#3709)
* Search labels #fix https://github.com/FreshRSS/FreshRSS/issues/3704 * Documentation * Allow list without quotes * Allow boolean AND searches * Allow searching any label * fix labels alias
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php102
1 files changed, 80 insertions, 22 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 046dc4afc..86f3ac040 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -732,25 +732,6 @@ SQL;
}
$sub_search = '';
- if ($filter->getFeedIds()) {
- $sub_search .= 'AND ' . $alias . 'id_feed IN (';
- foreach ($filter->getFeedIds() as $feed_id) {
- $sub_search .= '?,';
- $values[] = $feed_id;
- }
- $sub_search = rtrim($sub_search, ',');
- $sub_search .= ') ';
- }
- if ($filter->getNotFeedIds()) {
- $sub_search .= 'AND ' . $alias . 'id_feed NOT IN (';
- foreach ($filter->getNotFeedIds() as $feed_id) {
- $sub_search .= '?,';
- $values[] = $feed_id;
- }
- $sub_search = rtrim($sub_search, ',');
- $sub_search .= ') ';
- }
-
if ($filter->getMinDate()) {
$sub_search .= 'AND ' . $alias . 'id >= ? ';
$values[] = "{$filter->getMinDate()}000000";
@@ -800,6 +781,83 @@ SQL;
$sub_search .= ') ';
}
+ if ($filter->getFeedIds()) {
+ foreach ($filter->getFeedIds() as $feed_ids) {
+ $sub_search .= 'AND ' . $alias . 'id_feed IN (';
+ foreach ($feed_ids as $feed_id) {
+ $sub_search .= '?,';
+ $values[] = $feed_id;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ') ';
+ }
+ }
+ if ($filter->getNotFeedIds()) {
+ foreach ($filter->getNotFeedIds() as $feed_ids) {
+ $sub_search .= 'AND ' . $alias . 'id_feed NOT IN (';
+ foreach ($feed_ids as $feed_id) {
+ $sub_search .= '?,';
+ $values[] = $feed_id;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ') ';
+ }
+ }
+
+ if ($filter->getLabelIds()) {
+ foreach ($filter->getLabelIds() as $label_ids) {
+ if ($label_ids === '*') {
+ $sub_search .= 'AND EXISTS (SELECT et.id_tag FROM `_entrytag` et WHERE et.id_entry = ' . $alias . 'id) ';
+ } else {
+ $sub_search .= 'AND ' . $alias . 'id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (';
+ foreach ($label_ids as $label_id) {
+ $sub_search .= '?,';
+ $values[] = $label_id;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ')) ';
+ }
+ }
+ }
+ if ($filter->getNotLabelIds()) {
+ foreach ($filter->getNotLabelIds() as $label_ids) {
+ if ($label_ids === '*') {
+ $sub_search .= 'AND NOT EXISTS (SELECT et.id_tag FROM `_entrytag` et WHERE et.id_entry = ' . $alias . 'id) ';
+ } else {
+ $sub_search .= 'AND ' . $alias . 'id NOT IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (';
+ foreach ($label_ids as $label_id) {
+ $sub_search .= '?,';
+ $values[] = $label_id;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ')) ';
+ }
+ }
+ }
+
+ if ($filter->getLabelNames()) {
+ foreach ($filter->getLabelNames() as $label_names) {
+ $sub_search .= 'AND ' . $alias . 'id IN (SELECT et.id_entry FROM `_entrytag` et, `_tag` t WHERE et.id_tag = t.id AND t.name IN (';
+ foreach ($label_names as $label_name) {
+ $sub_search .= '?,';
+ $values[] = $label_name;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ')) ';
+ }
+ }
+ if ($filter->getNotLabelNames()) {
+ foreach ($filter->getNotLabelNames() as $label_names) {
+ $sub_search .= 'AND ' . $alias . 'id NOT IN (SELECT et.id_entry FROM `_entrytag` et, `_tag` t WHERE et.id_tag = t.id AND t.name IN (';
+ foreach ($label_names as $label_name) {
+ $sub_search .= '?,';
+ $values[] = $label_name;
+ }
+ $sub_search = rtrim($sub_search, ',');
+ $sub_search .= ')) ';
+ }
+ }
+
if ($filter->getAuthor()) {
foreach ($filter->getAuthor() as $author) {
$sub_search .= 'AND ' . $alias . 'author LIKE ? ';
@@ -913,14 +971,14 @@ SQL;
$where .= 'e.id_feed=? ';
$values[] = intval($id);
break;
- case 't': //Tag
+ case 't': //Tag (label)
$where .= 'et.id_tag=? ';
$values[] = intval($id);
break;
- case 'T': //Any tag
+ case 'T': //Any tag (label)
$where .= '1=1 ';
break;
- case 'ST': //Starred or tagged
+ case 'ST': //Starred or tagged (label)
$where .= 'e.is_favorite=1 OR EXISTS (SELECT et2.id_tag FROM `_entrytag` et2 WHERE et2.id_entry = e.id) ';
break;
default: