public function DiscussionSql($SearchModel, $AddMatch = TRUE) {
		// Get permission and limit search categories if necessary.
      if ($AddMatch) {
         $Perms = CategoryModel::CategoryWatch();
         
         if($Perms !== TRUE) {
            $this->SQL->WhereIn('d.CategoryID', $Perms);
         }
		
         // Build search part of query.
         $SearchModel->AddMatchSql($this->SQL, 'd.Name, d.Body', 'd.DateInserted');
      }
		
		// Build base query
		$this->SQL
			->Select('d.DiscussionID as PrimaryID, d.Name as Title, d.Body as Summary, d.Format, d.CategoryID, d.Score')
			->Select('d.DiscussionID', "concat('/discussion/', %s)", 'Url')
			->Select('d.DateInserted')
			->Select('d.InsertUserID as UserID')
         ->Select("'Discussion'", '', 'RecordType')
			->From('Discussion d');

      if ($AddMatch) {
         // Execute query.
         $Result = $this->SQL->GetSelect();

         // Unset SQL
         $this->SQL->Reset();
      } else {
         $Result = $this->SQL;
      }
		
		return $Result;
	}