original_string: 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;
  	}
code: 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;
  	}
code_tokens: 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 ; }
docstring: Execute discussion search query.
  
  @since 2.0.0
  @access public
  
  @param object $SearchModel SearchModel (Dashboard)
  @return object SQL result.
docstring_tokens: Execute discussion search query .