Index: core/filter_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v
retrieving revision 1.163
diff -u -b -r1.163 filter_api.php
--- core/filter_api.php	15 Sep 2007 21:48:26 -0000	1.163
+++ core/filter_api.php	17 Sep 2007 13:59:49 -0000
@@ -1245,26 +1245,19 @@
 			$t_where	= '';
 		}
 
-		# Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
-		# have bugnotes that match the text search if necessary.
+
 		$t_id_array = array();
-		for ( $i = 0; $i < 2; $i++ ) {
 			$t_id_where = $t_where;
 			$t_id_join = $t_join;
-			if ( $i == 0 ) {
-				if ( !is_blank( $t_id_where ) && !is_blank( $t_textsearch_where_clause ) ) {
-					$t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
-				}
-			} else if ( !is_blank( $t_textsearch_wherejoin_clause ) ) {
+            if ( !is_blank( $t_textsearch_wherejoin_clause ) ) {
 				$t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
-				$t_id_join = $t_id_join . " INNER JOIN $t_bugnote_table ON $t_bugnote_table.bug_id = $t_bug_table.id";
-				$t_id_join = $t_id_join . " INNER JOIN $t_bugnote_text_table ON $t_bugnote_text_table.id = $t_bugnote_table.bugnote_text_id";
+				$t_id_join = $t_id_join . " LEFT JOIN $t_bugnote_table ON $t_bugnote_table.bug_id = $t_bug_table.id";
+				$t_id_join = $t_id_join . " LEFT JOIN $t_bugnote_text_table ON $t_bugnote_text_table.id = $t_bugnote_table.bugnote_text_id";
 			}
 			$query  = "SELECT DISTINCT $t_bug_table.id AS id
 						$t_from
 						$t_id_join
 						$t_id_where";
-			if ( ( $i == 0 ) || ( !is_blank( $t_textsearch_wherejoin_clause ) ) ) {
 				$result = db_query( $query );
 				$row_count = db_num_rows( $result );
 
@@ -1272,10 +1265,7 @@
 					$row = db_fetch_array( $result );
 					$t_id_array[] = db_prepare_int ( $row['id'] );
 				}
-			}
-		}
 
-		$t_id_array = array_unique( $t_id_array );
 
 		# Get the total number of bugs that meet the criteria.
 		$bug_count = count( $t_id_array );
@@ -1283,7 +1273,7 @@
 		$rows = array();
 
 		if ( $bug_count > 0 ) {
-			$t_where = "WHERE $t_bug_table.id in (" . implode( ", ", $t_id_array ) . ")";
+        	$t_where = "WHERE $t_bug_table.id in (" .$query . ")";
 		} else {
 			return $rows;
 		}
@@ -1420,7 +1410,9 @@
 		// paulr: it should be impossible for t_id_array_lastmod to be array():
 		// that would imply that $t_id_array is null which aborts this function early
 		//if ( count( $t_id_array_lastmod ) > 0 ) {
-		$t_where = "WHERE $t_bugnote_table.bug_id in (" . implode( ", ", $t_id_array_lastmod ) . ")";
+		//$t_where = "WHERE $t_bugnote_table.bug_id in (" . implode( ", ", $t_id_array_lastmod ) . ")";
+		$t_where = "WHERE $t_bugnote_table.bug_id in (" . $query . ")";
+
 		
 		$query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM $t_bugnote_table $t_where GROUP BY bug_id";
 
