]> git.wh0rd.org Git - tt-rss.git/commitdiff
search: simplify code, allow searching by note and title content (note:blah, title...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 4 Apr 2013 12:52:25 +0000 (16:52 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 4 Apr 2013 12:52:25 +0000 (16:52 +0400)
include/functions.php

index 82c53fc31a46ef024f073567f67ab99989606010..6f5db9a5f4802571ed436625c497798665828247 100644 (file)
 
                        $commandpair = explode(":", mb_strtolower($k), 2);
 
-                       if ($commandpair[0] == "note" && $commandpair[1]) {
-
-                               if ($commandpair[1] == "true")
-                                       array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))");
-                               else if ($commandpair[1] == "false")
-                                       array_push($query_keywords, "($not (note IS NULL OR note = ''))");
-                               else
-                                       array_push($query_keywords, "($not (note LIKE '%".
-                                               db_escape_string($link, $commandpair[1])."%'))");
-
-                       } else if ($commandpair[0] == "star" && $commandpair[1]) {
-
-                               if ($commandpair[1] == "true")
-                                       array_push($query_keywords, "($not (marked = true))");
-                               else
-                                       array_push($query_keywords, "($not (marked = false))");
-
-                       } else if ($commandpair[0] == "pub" && $commandpair[1]) {
+                       switch ($commandpair[0]) {
+                       case "title":
+                               if ($commandpair[1]) {
+                                       array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE '%".
+                                               db_escape_string($link, mb_strtolower($commandpair[1]))."%'))");
+                               }
+                               break;
+                       case "author":
+                               if ($commandpair[1]) {
+                                       array_push($query_keywords, "($not (LOWER(author) LIKE '%".
+                                               db_escape_string($link, mb_strtolower($commandpair[1]))."%'))");
+                               }
+                               break;
+                       case "note":
+                               if ($commandpair[1]) {
+                                       if ($commandpair[1] == "true")
+                                               array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))");
+                                       else if ($commandpair[1] == "false")
+                                               array_push($query_keywords, "($not (note IS NULL OR note = ''))");
+                                       else
+                                               array_push($query_keywords, "($not (LOWER(note) LIKE '%".
+                                                       db_escape_string($link, mb_strtolower($commandpair[1]))."%'))");
+                               }
+                               break;
+                       case "star":
 
-                               if ($commandpair[1] == "true")
-                                       array_push($query_keywords, "($not (published = true))");
-                               else
-                                       array_push($query_keywords, "($not (published = false))");
+                               if ($commandpair[1]) {
+                                       if ($commandpair[1] == "true")
+                                               array_push($query_keywords, "($not (marked = true))");
+                                       else
+                                               array_push($query_keywords, "($not (marked = false))");
+                               }
+                               break;
+                       case "pub":
+                               if ($commandpair[1]) {
+                                       if ($commandpair[1] == "true")
+                                               array_push($query_keywords, "($not (published = true))");
+                                       else
+                                               array_push($query_keywords, "($not (published = false))");
 
-                       } else if (strpos($k, "@") === 0) {
+                               }
+                               break;
+                       default:
+                               if (strpos($k, "@") === 0) {
 
-                               $user_tz_string = get_pref($link, 'USER_TIMEZONE', $_SESSION['uid']);
-                               $orig_ts = strtotime(substr($k, 1));
-                               $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC'));
+                                       $user_tz_string = get_pref($link, 'USER_TIMEZONE', $_SESSION['uid']);
+                                       $orig_ts = strtotime(substr($k, 1));
+                                       $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC'));
 
-                               //$k = date("Y-m-d", strtotime(substr($k, 1)));
+                                       //$k = date("Y-m-d", strtotime(substr($k, 1)));
 
-                               array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')");
-                       } else {
-                               array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
-                                               OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+                                       array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')");
+                               } else {
+                                       array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
+                                                       OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+                               }
                        }
                }