From 35a87b7ecce6ff6be3ca9f94ec1aa453347950b5 Mon Sep 17 00:00:00 2001
From: meeuw <dick@mrns.nl>
Date: Wed, 23 Feb 2011 10:37:45 +0100
Subject: [PATCH] fix for mantisbt.org issue 12787 - negate text search doesn't work for multiple bug notes

---
 core/filter_api.php |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/core/filter_api.php b/core/filter_api.php
index 0c6d5b7..6604712 100644
--- a/core/filter_api.php
+++ b/core/filter_api.php
@@ -1973,7 +1973,10 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
 				' OR ' . db_helper_like( "$t_bug_text_table.description" ) .
 				' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce" ) .
 				' OR ' . db_helper_like( "$t_bug_text_table.additional_information" ) .
-				' OR ' . db_helper_like( "$t_bugnote_text_table.note" );
+				' OR ' . "$t_bug_table.id" . " IN (".
+					"SELECT bug_id FROM $t_bugnote_table".
+					" LEFT JOIN $t_bugnote_text_table ON $t_bugnote_table.bugnote_text_id = $t_bugnote_text_table.id".
+					" WHERE ($t_bugnote_text_table.note LIKE ".db_param()."))";
 
 			$t_where_params[] = $c_search;
 			$t_where_params[] = $c_search;
@@ -1997,10 +2000,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
 		# add text query elements to arrays
 		if ( !$t_first ) {
 			$t_from_clauses[] = "$t_bug_text_table";
-			$t_where_clauses[] = "$t_bug_table.bug_text_id = $t_bug_text_table.id";
 			$t_where_clauses[] = $t_textsearch_where_clause;
-			$t_join_clauses[] = " LEFT JOIN $t_bugnote_table ON $t_bug_table.id = $t_bugnote_table.bug_id";
-			$t_join_clauses[] = " LEFT JOIN $t_bugnote_text_table ON $t_bugnote_table.bugnote_text_id = $t_bugnote_text_table.id";
 		}
 	}
 
-- 
1.7.3.4

