From e20c9d88c057d28e4e80e85f810adc79943e2dcd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 31 Jul 2006 08:50:34 +0100 Subject: [PATCH] improved keyword search --- functions.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 4b118f4b..686cecfe 100644 --- a/functions.php +++ b/functions.php @@ -1931,14 +1931,34 @@ function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on) { if ($search) { + + $keywords = split(" ", $search); + $query_keywords = array(); + if ($match_on == "both") { - $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%') - OR upper(ttrss_entries.content) LIKE '%$search%') AND"; + + foreach ($keywords as $k) { + array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%') + OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); + } + + $search_query_part = implode("AND", $query_keywords) . "AND"; + } else if ($match_on == "title") { - $search_query_part = "upper(ttrss_entries.title) LIKE upper('%$search%') - AND"; + + foreach ($keywords as $k) { + array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))"); + } + + $search_query_part = implode("AND", $query_keywords) . "AND"; + } else if ($match_on == "content") { - $search_query_part = "upper(ttrss_entries.content) LIKE upper('%$search%') AND"; + + foreach ($keywords as $k) { + array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); + } + + $search_query_part = implode("AND", $query_keywords) . "AND"; } } else { $search_query_part = ""; -- 2.39.5