From 1638fc4e13e1d71eceb1deefe983c7f48d47b8a1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 7 Oct 2009 15:12:21 +0400 Subject: prefs: rudimentary multiple keyword search --- modules/pref-feeds.php | 18 +++++++++++++++--- modules/pref-filters.php | 24 +++++++++++++++++------- modules/pref-labels.php | 14 +++++++++++++- modules/pref-users.php | 12 +++++++++++- 4 files changed, 56 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index ce12806ee..b0269243e 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1184,9 +1184,21 @@ $_SESSION["pref_sort_feeds"] = $feeds_sort; if ($feed_search) { - $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR - UPPER(C1.title) LIKE UPPER('%$feed_search%') OR - UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND"; + + $feed_search = split(" ", $feed_search); + $tokens = array(); + + foreach ($feed_search as $token) { + + $token = trim($token); + + array_push($tokens, "(UPPER(F1.title) LIKE UPPER('%$token%') OR + UPPER(C1.title) LIKE UPPER('%$token%') OR + UPPER(F1.feed_url) LIKE UPPER('%$token%'))"); + } + + $search_qpart = "(" . join($tokens, " AND ") . ") AND "; + } else { $search_qpart = ""; } diff --git a/modules/pref-filters.php b/modules/pref-filters.php index 9e3e100f1..238ceb151 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -324,13 +324,23 @@ value=\"".__('Rescore articles')."\">"; if ($filter_search) { - $filter_search = db_escape_string($filter_search); - $filter_search_query = "( - UPPER(ttrss_filter_actions.description) LIKE UPPER('%$filter_search%') OR - UPPER(reg_exp) LIKE UPPER('%$filter_search%') OR - UPPER(action_param) LIKE UPPER('%$filter_search%') OR - UPPER(ttrss_feeds.title) LIKE UPPER('%$filter_search%') OR - UPPER(ttrss_filter_types.description) LIKE UPPER('%$filter_search%')) AND"; + $filter_search = split(' ', db_escape_string($filter_search)); + + $tokens = array(); + + foreach ($filter_search as $token) { + $token = trim($token); + + array_push($tokens, "( + UPPER(ttrss_filter_actions.description) LIKE UPPER('%$token%') OR + UPPER(reg_exp) LIKE UPPER('%$token%') OR + UPPER(action_param) LIKE UPPER('%$token%') OR + UPPER(ttrss_feeds.title) LIKE UPPER('%$token%') OR + UPPER(ttrss_filter_types.description) LIKE UPPER('%$token%'))"); + } + + $filter_search_query = "(" . join($tokens, " AND ") . ") AND "; + } else { $filter_search_query = ""; } diff --git a/modules/pref-labels.php b/modules/pref-labels.php index 165765b89..336228801 100644 --- a/modules/pref-labels.php +++ b/modules/pref-labels.php @@ -138,7 +138,19 @@ value=\"".__('Create label')."\">"; if ($label_search) { - $label_search_query = "caption LIKE '%$label_search%' AND"; + + $label_search = split(" ", $label_search); + $tokens = array(); + + foreach ($label_search as $token) { + + $token = trim($token); + array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))"); + + } + + $label_search_query = "(" . join($tokens, " AND ") . ") AND "; + } else { $label_search_query = ""; } diff --git a/modules/pref-users.php b/modules/pref-users.php index 7e38fd5d4..7a878b18f 100644 --- a/modules/pref-users.php +++ b/modules/pref-users.php @@ -374,7 +374,17 @@ onclick=\"javascript:addUser()\" value=\"".__('Create user')."\">"; if ($user_search) { - $user_search_query = "UPPER(login) LIKE UPPER('%$user_search%') AND"; + + $user_search = split(" ", $user_search); + $tokens = array(); + + foreach ($user_search as $token) { + $token = trim($token); + array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))"); + } + + $user_search_query = "(" . join($tokens, " AND ") . ") AND "; + } else { $user_search_query = ""; } -- cgit v1.2.3