simplify searching query

This commit is contained in:
Andrew Dolgov 2012-09-24 12:01:42 +04:00
parent 759e5132a1
commit 7032f2a598
1 changed files with 16 additions and 30 deletions

View File

@ -2364,40 +2364,29 @@
// override query strategy and enable feed display when searching globally // override query strategy and enable feed display when searching globally
if ($search && $search_mode == "all_feeds") { if ($search && $search_mode == "all_feeds") {
$query_strategy_part = "ttrss_entries.id > 0"; $query_strategy_part = "true";
$vfeed_query_part = "ttrss_feeds.title AS feed_title,"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
/* tags */ /* tags */
} else if (!is_numeric($feed)) { } else if (!is_numeric($feed)) {
$query_strategy_part = "ttrss_entries.id > 0"; $query_strategy_part = "true";
$vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
id = feed_id) as feed_title,"; id = feed_id) as feed_title,";
} else if ($feed > 0 && $search && $search_mode == "this_cat") { } else if ($search && $search_mode == "this_cat") {
$vfeed_query_part = "ttrss_feeds.title AS feed_title,"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
$tmp_result = false; if ($feed > 0) {
if ($include_children) {
if ($cat_view) { $subcats = getChildCategories($link, $feed, $owner_uid);
$tmp_result = db_query($link, "SELECT id array_push($subcats, $feed);
FROM ttrss_feeds WHERE cat_id = '$feed'"); $cats_qpart = join(",", $subcats);
} else { } else {
$tmp_result = db_query($link, "SELECT id $cats_qpart = $feed;
FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds
WHERE id = '$feed') AND id != '$feed'");
} }
$cat_siblings = array(); $query_strategy_part = "ttrss_feeds.cat_id IN ($cats_qpart)";
if (db_num_rows($tmp_result) > 0) {
while ($p = db_fetch_assoc($tmp_result)) {
array_push($cat_siblings, "feed_id = " . $p["id"]);
}
$query_strategy_part = sprintf("(feed_id = %d OR %s)",
$feed, implode(" OR ", $cat_siblings));
} else { } else {
$query_strategy_part = "ttrss_entries.id > 0"; $query_strategy_part = "ttrss_feeds.cat_id IS NULL";
} }
} else if ($feed > 0) { } else if ($feed > 0) {
@ -2409,13 +2398,10 @@
# sub-cats # sub-cats
$subcats = getChildCategories($link, $feed, $owner_uid); $subcats = getChildCategories($link, $feed, $owner_uid);
if (count($subcats) == 0) {
$query_strategy_part = "cat_id = '$feed'";
} else {
array_push($subcats, $feed); array_push($subcats, $feed);
$query_strategy_part = "cat_id IN (". $query_strategy_part = "cat_id IN (".
implode(",", $subcats).")"; implode(",", $subcats).")";
}
} else { } else {
$query_strategy_part = "cat_id = '$feed'"; $query_strategy_part = "cat_id = '$feed'";
} }
@ -2512,7 +2498,7 @@
$feed_title = ""; $feed_title = "";
if ($search) { if ($search) {
$feed_title = "Search results"; $feed_title = T_sprintf("Search results: %s", $search);
} else { } else {
if ($cat_view) { if ($cat_view) {
$feed_title = getCategoryTitle($link, $feed); $feed_title = getCategoryTitle($link, $feed);