]> git.wh0rd.org Git - tt-rss.git/commitdiff
getSearchSql: support excluding keywords with -
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 18 Jan 2010 13:03:45 +0000 (16:03 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 18 Jan 2010 13:03:45 +0000 (16:03 +0300)
functions.php

index 398540dfad36b741c5f169dd53c413b40d9e81f1..c7bf4eaa37913bc2165e5e015b51ad92f981891b 100644 (file)
                if ($match_on == "both") {
 
                        foreach ($keywords as $k) {
-                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
-                                       OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
+                               if (strpos($k, "-") === 0) {
+                                       $k = substr($k, 1);
+                                       $not = "NOT";
+                               } else {
+                                       $not = "";
+                               }
+
+                               array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
+                                       OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
                        }
 
                        $search_query_part = implode("AND", $query_keywords) . " AND ";
                } else if ($match_on == "title") {
 
                        foreach ($keywords as $k) {
-                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
+                               if (strpos($k, "-") === 0) {
+                                       $k = substr($k, 1);
+                                       $not = "NOT";
+                               } else {
+                                       $not = "";
+                               }
+
+                               array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%'))");
                        }
 
                        $search_query_part = implode("AND", $query_keywords) . " AND ";
                } else if ($match_on == "content") {
 
                        foreach ($keywords as $k) {
-                               array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
+                               if (strpos($k, "-") === 0) {
+                                       $k = substr($k, 1);
+                                       $not = "NOT";
+                               } else {
+                                       $not = "";
+                               }
+
+                               array_push($query_keywords, "(UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
                        }
                }