[Fusionforge-commits] r14564 - in branches/Branch_5_1: . src/common/search

Roland Mas lolando at fusionforge.org
Fri Oct 7 16:30:04 CEST 2011


Author: lolando
Date: 2011-10-07 16:30:04 +0200 (Fri, 07 Oct 2011)
New Revision: 14564

Modified:
   branches/Branch_5_1/
   branches/Branch_5_1/src/common/search/TrackersSearchQuery.class.php
Log:
Fix cross-field searches for trackers

Modified: branches/Branch_5_1/src/common/search/TrackersSearchQuery.class.php
===================================================================
--- branches/Branch_5_1/src/common/search/TrackersSearchQuery.class.php	2011-10-07 14:29:53 UTC (rev 14563)
+++ branches/Branch_5_1/src/common/search/TrackersSearchQuery.class.php	2011-10-07 14:30:04 UTC (rev 14564)
@@ -65,67 +65,72 @@
 	 * @return array query+params array
 	 */
 	function getQuery() {
-
-		
 		$qpa = db_construct_qpa () ;
 
+		$words = $this->getFTIwords();
+
+		$qpa = db_construct_qpa ($qpa,
+					 'SELECT x.* FROM (SELECT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_group_list.name, artifact.summary||$1||artifact.details||$1||coalesce(string_agg(artifact_message.body, $1), $2) as full_string_agg',
+						 array (' //// ', ' '));
 		if (forge_get_config('use_fti')) {
 			$qpa = db_construct_qpa ($qpa,
-						 'SELECT DISTINCT x.* FROM (SELECT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_group_list.name, (ts_rank(artifact_idx.vectors, q)+ts_rank(artifact_message_idx.vectors, q)) AS rank FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users, artifact_group_list, to_tsquery($1) q, artifact_idx, artifact_message_idx WHERE users.user_id = artifact.submitted_by AND artifact_idx.artifact_id = artifact.artifact_id AND artifact_message_idx.id = artifact_message.id AND artifact_message_idx.artifact_id = artifact_message_idx.artifact_id AND artifact_group_list.group_artifact_id = artifact.group_artifact_id AND artifact_group_list.group_id = $2 AND (artifact_idx.vectors @@ q OR artifact_message_idx.vectors @@ q)',
-						 array ($this->getFTIwords(),
-							$this->groupId)) ;
+						 ', (artifact_idx.vectors || coalesce(ff_tsvector_agg(artifact_message_idx.vectors), $2::tsvector)) AS full_vector_agg');
+						 }
+		$qpa = db_construct_qpa ($qpa, 
+					 ' FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users, artifact_group_list',
+						 array ()) ;
+		if (forge_get_config('use_fti')) {
+			$qpa = db_construct_qpa ($qpa, 
+						 ', artifact_idx, artifact_message_idx',
+						 array ()) ;
+		}
+		$qpa = db_construct_qpa ($qpa, 
+					 ' WHERE users.user_id = artifact.submitted_by AND artifact_group_list.group_artifact_id = artifact.group_artifact_id AND artifact_group_list.group_id = $1 ',
+						 array ($this->groupId)) ;
+		if ($this->sections != SEARCH__ALL_SECTIONS) {
+			$qpa = db_construct_qpa ($qpa,
+						 'AND artifact_group_list.group_artifact_id = ANY ($1) ',
+						 array (db_int_array_to_any_clause ($this->sections))) ;
+		}
+		if (!$this->showNonPublic) {
+			$qpa = db_construct_qpa ($qpa,
+						 'AND artifact_group_list.is_public = 1 ') ;
+		}
+		if (forge_get_config('use_fti')) {
+			$qpa = db_construct_qpa ($qpa, 
+						 'AND artifact.artifact_id = artifact_idx.artifact_id AND artifact_message.id = artifact_message_idx.id ',
+						 array ()) ;
+		}
+		$qpa = db_construct_qpa ($qpa,
+					 'GROUP BY artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_group_list.name') ;
 
+		if (forge_get_config('use_fti')) {
+			$qpa = db_construct_qpa ($qpa, 
+						 ', artifact_idx.vectors',
+						 array ()) ;
+		}
+		$qpa = db_construct_qpa ($qpa, 
+					 ') AS x WHERE ') ;
+		
+		if (forge_get_config('use_fti')) {
+			$qpa = db_construct_qpa ($qpa,
+						 'full_vector_agg @@ $1 ',
+						 array($words));
 			if (count($this->phrases)) {
 				$qpa = db_construct_qpa ($qpa,
-							 'AND ((') ;
-				$qpa = $this->addMatchCondition($qpa, 'artifact.details');
+							 'AND (') ;
+				$qpa = $this->addMatchCondition ($qpa, 'x.full_string_agg') ;
 				$qpa = db_construct_qpa ($qpa,
-							 ') OR (') ;
-				$qpa = $this->addMatchCondition($qpa, 'artifact.summary');
-				$qpa = db_construct_qpa ($qpa,
-							 ') OR (') ;
-				$qpa = $this->addMatchCondition($qpa, 'artifact_message.body');
-				$qpa = db_construct_qpa ($qpa,
-							 ')) ') ;
+							 ') ') ;
 			}
-			if ($this->sections != SEARCH__ALL_SECTIONS) {
-				$qpa = db_construct_qpa ($qpa,
-							 'AND artifact_group_list.group_artifact_id = ANY ($1) ',
-							 array( db_int_array_to_any_clause ($this->sections))) ;
-			}
-			if (!$this->showNonPublic) {
-				$qpa = db_construct_qpa ($qpa,
-							 'AND artifact_group_list.is_public = 1 ') ;
-			}
 			$qpa = db_construct_qpa ($qpa,
-						 ') AS x ') ;
-			$qpa = db_construct_qpa ($qpa,
-						 'ORDER BY rank DESC') ;
+						 'ORDER BY ts_rank(full_vector_agg, $1) DESC',
+						 array($words)) ;
+			
 		} else {
+			$qpa = $this->addIlikeCondition ($qpa, 'x.full_string_agg') ;
 			$qpa = db_construct_qpa ($qpa,
-						 'SELECT DISTINCT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_group_list.name FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users, artifact_group_list WHERE users.user_id = artifact.submitted_by AND artifact_group_list.group_artifact_id = artifact.group_artifact_id AND artifact_group_list.group_id = $1 ',
-						 array ($this->groupId)) ;
-			if ($this->sections != SEARCH__ALL_SECTIONS) {
-				$qpa = db_construct_qpa ($qpa,
-							 'AND artifact_group_list.group_artifact_id = ANY ($1) ',
-							 array(db_int_array_to_any_clause ($this->sections))) ;
-			}
-			if (!$this->showNonPublic) {
-				$qpa = db_construct_qpa ($qpa,
-							 'AND artifact_group_list.is_public = 1 ') ;
-			}
-
-			$qpa = db_construct_qpa ($qpa,
-						 ' AND ((') ;
-			$qpa = $this->addIlikeCondition ($qpa, 'artifact.details') ;
-			$qpa = db_construct_qpa ($qpa,
-						 ') OR (') ;
-			$qpa = $this->addIlikeCondition ($qpa, 'artifact.summary') ;
-			$qpa = db_construct_qpa ($qpa,
-						 ') OR (') ;
-			$qpa = $this->addIlikeCondition ($qpa, 'artifact_message.body') ;
-			$qpa = db_construct_qpa ($qpa,
-						 ')) ORDER BY artifact_group_list.name, artifact.artifact_id') ;
+						 'ORDER BY x.name, x.artifact_id') ;
 		}
 		return $qpa ;
 	}




More information about the Fusionforge-commits mailing list