gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/common/search NewsSearchQuery.class, NONE, 1.1 F


From: gsmet
Subject: [Gforge-commits] gforge/common/search NewsSearchQuery.class, NONE, 1.1 ForumsSearchQuery.class, NONE, 1.1 TrackersSearchQuery.class, NONE, 1.1 SearchQuery.class, 1.2, 1.3 FrsSearchQuery.class, NONE, 1.1 TasksSearchQuery.class, NONE, 1.1 DocsSearchQuery.class, NONE, 1.1
Date: Tue, 12 Oct 2004 17:06:28 -0500

Update of /cvsroot/gforge/gforge/common/search
In directory db.perdue.net:/tmp/cvs-serv2331/common/search

Modified Files:
        SearchQuery.class 
Added Files:
        NewsSearchQuery.class ForumsSearchQuery.class 
        TrackersSearchQuery.class FrsSearchQuery.class 
        TasksSearchQuery.class DocsSearchQuery.class 
Log Message:
first part of GUS heavily based on [#833] Grand Unified Search by Dominik Haas

--- NEW FILE: NewsSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: NewsSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */

require_once('common/search/SearchQuery.class');

class NewsSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         */
        function NewsSearchQuery($words, $offset, $isExact, $groupId) { 
                $this->groupId = $groupId;
                
                $this->SearchQuery($words, $offset, $isExact);
        }

        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {
                $sql = 'SELECT news_bytes.summary, news_bytes.post_date, 
news_bytes.forum_id, users.realname'
                        . ' FROM news_bytes, users'
                        . ' WHERE (group_id='.$this->groupId.' AND is_approved 
<> \'4\' AND news_bytes.submitted_by = users.user_id' 
                        . ' AND (('.$this->getIlikeCondition('summary', 
$this->words).')' 
                        . ' OR ('.$this->getIlikeCondition('details', 
$this->words).')))'
                        . ' ORDER BY post_date DESC';
                return $sql;
        }
}

?>
--- NEW FILE: ForumsSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: ForumsSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */
 
require_once('common/search/SearchQuery.class');

class ForumsSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
        * flag if non public items are returned
        *
        * @var boolean $showNonPublic
        */      
        var $showNonPublic;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param array $sections sections to search in
         * @param boolean $showNonPublic flag if private sections are searched 
too
         */
        function ForumsSearchQuery($words, $offset, $isExact, $groupId, 
$sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
                $this->groupId = $groupId;
                $this->showNonPublic = $showNonPublic;
                
                $this->SearchQuery($words, $offset, $isExact);
                
                $this->setSections($sections);
        }

        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {
                $sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, 
users.realname, forum_group_list.forum_name '
                        . 'FROM forum, users, forum_group_list '
                        . 'WHERE users.user_id = forum.posted_by '
                        . 'AND forum_group_list.group_forum_id = 
forum.group_forum_id '
                        . 'AND forum_group_list.is_public <> 9 '                
        
                        . 'AND forum.group_forum_id IN (SELECT group_forum_id 
FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
                if ($this->sections != SEARCH__ALL_SECTIONS) {
                        $sql .= 'AND forum_group_list.forum_name IN 
('.$this->sections.') ';
                }
                if (!$this->showNonPublic) {
                        $sql .= 'AND forum_group_list.is_public = 1 ';
                }
                $sql .= 'AND (('.$this->getIlikeCondition('forum.body', 
$this->words).') '
                        . 'OR ('.$this->getIlikeCondition('forum.subject', 
$this->words).')) '
                        . 'ORDER BY forum_group_list.forum_name, forum.msg_id';
                
                return $sql;
        }

        /**
         * getSearchByIdQuery - get the sql query built to get the search 
results when we are looking for an int
         *
         * @return string sql query to execute
         */     
        function getSearchByIdQuery() {
                $sql = 'SELECT msg_id '
                        . 'FROM forum, forum_group_list '
                        . 'WHERE msg_id=\''.$this->searchId.'\' '
                        . 'AND forum_group_list.group_forum_id = 
forum.group_forum_id '
                        . 'AND group_forum_id=\''.$this->forumId.'\'';
                if (!$this->showNonPublic) {
                        $sql .= ' AND forum_group_list.is_public = 1';
                }

                return $sql;
        }
        
        /**
         * getSections - returns the list of available forums
         *
         * @param $groupId int group id
         * @param $showNonPublic boolean if we should consider non public 
sections
         */
        function getSections($groupId, $showNonPublic=false) {
                $sql = 'SELECT group_forum_id, forum_name FROM forum_group_list 
WHERE group_id = '.$groupId.' AND is_public <> 9';
                if (!$showNonPublic) {
                        $sql .= ' AND is_public = 1';
                }
                $sql .= ' ORDER BY forum_name';
                
                $sections = array();
                $res = db_query($sql);
                while($data = db_fetch_array($res)) {
                        $sections[$data['group_forum_id']] = 
$data['forum_name'];
                }
                return $sections;
        }
}

?>
--- NEW FILE: TrackersSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: TrackersSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */

require_once('common/search/SearchQuery.class');

class TrackersSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
        * flag if non public items are returned
        *
        * @var boolean $showNonPublic
        */      
        var $showNonPublic;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param array $sections sections to search in
         * @param boolean $showNonPublic flag if private sections are searched 
too
         */
        function TrackersSearchQuery($words, $offset, $isExact, $groupId, 
$sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
                $this->groupId = $groupId;
                $this->showNonPublic = $showNonPublic;
                
                $this->SearchQuery($words, $offset, $isExact);

                $this->setSections($sections);
        }

        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {

                $sql = '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 = 
'.$this->groupId.' ';
                if ($this->sections != SEARCH__ALL_SECTIONS) {
                        $sql .= 'AND artifact_group_list.name in 
('.$this->sections.') ';
                }
                if (!$this->showNonPublic) {
                        $sql .= 'AND artifact_group_list.is_public = 1 ';
                }
                $sql .= 'AND (('.$this->getIlikeCondition('artifact.details', 
$this->words).') ' 
                        . 'OR ('.$this->getIlikeCondition('artifact.summary', 
$this->words).') '
                        . 'OR 
('.$this->getIlikeCondition('artifact_message.body', $this->words).')) '
                        . 'ORDER BY artifact_group_list.name, 
artifact.artifact_id';

                return $sql;
        }
        
        /**
         * getSections - returns the list of available trackers
         *
         * @param $groupId int group id
         * @param $showNonPublic boolean if we should consider non public 
sections
         */
        function getSections($groupId, $showNonPublic=false) {
                $sql = 'SELECT group_artifact_id, name FROM artifact_group_list 
WHERE group_id = '.$groupId.'';
                if (!$showNonPublic) {
                        $sql .= ' AND artifact_group_list.is_public = 1';
                }
                $sql .= ' ORDER BY name';
                
                $sections = array();
                $res = db_query($sql);
                while($data = db_fetch_array($res)) {
                        $sections[$data['doc_group']] = $data['groupname'];
                }
                return $sections;
        }
}

?>
Index: SearchQuery.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/search/SearchQuery.class,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SearchQuery.class   18 Feb 2004 09:45:21 -0000      1.2
+++ SearchQuery.class   12 Oct 2004 22:06:25 -0000      1.3
@@ -60,6 +60,12 @@
         * @var boolean $isExact
         */
         var $isExact = false;
+       /**
+        * sections to search in
+        *
+        * @var array $sections
+        */     
+       var $sections = SEARCH__ALL_SECTIONS;
 
        /**
         * Constructor
@@ -218,6 +224,22 @@
        function getWords() {
                return $this->words;
        }
+       
+       /**
+        * setSections - set the sections list
+        *
+        * @param $sections mixed array of sections or SEARCH__ALL_SECTIONS
+        */
+       function setSections($sections) {
+               if(is_array($sections)) {
+                       //make a comma separated string from the sections array
+                       foreach($sections as $key => $section) 
+                               $sections[$key] = '\''.$section.'\'';
+                       $this->sections = implode(', ', $sections);
+               } else {
+                       $this->sections = $sections;
+               }
+       }
 
 }
 

--- NEW FILE: FrsSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: FrsSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */

require_once('common/search/SearchQuery.class');

class FrsSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
        * flag if non public items are returned
        *
        * @var boolean $showNonPublic
        */      
        var $showNonPublic;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param array $sections sections to search in
         */
        function FrsSearchQuery($words, $offset, $isExact, $groupId, 
$sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {    
                $this->groupId = $groupId;
                $this->showNonPublic = $showNonPublic;
                
                $this->SearchQuery($words, $offset, $isExact);
                
                $this->setSections($sections);
        }
        
        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {
                $sql = 'SELECT frs_package.name as package_name, 
frs_release.name as release_name, frs_release.release_date, 
frs_release.release_id, users.realname'
                        . ' FROM frs_file, frs_release, users, frs_package'
                        . ' WHERE frs_release.released_by = users.user_id'
                        . ' AND frs_package.package_id = frs_release.package_id'
                        . ' AND frs_file.release_id=frs_release.release_id'
                        . ' AND frs_package.group_id='.$this->groupId;
                
                if ($this->sections != SEARCH__ALL_SECTIONS) {
                        $sql .= ' AND frs_package.name IN ('.$this->sections.') 
';
                }
                if(!$this->showNonPublic) {
                        $sql .= ' AND is_public=1';
                }

                $sql .= ' AND 
(('.$this->getIlikeCondition('frs_release.changes', $this->words).')' 
                        . ' OR ('.$this->getIlikeCondition('frs_release.notes', 
$this->words).')'
                        . ' OR ('.$this->getIlikeCondition('frs_release.name', 
$this->words).')'
                        . ' OR ('.$this->getIlikeCondition('frs_file.filename', 
$this->words).'))'
                        . ' ORDER BY frs_package.name, frs_release.name';

                return $sql;
        }
        
        /**
         * getSections - returns the list of available forums
         *
         * @param $groupId int group id
         * @param $showNonPublic boolean if we should consider non public 
sections
         */
        function getSections($groupId, $showNonPublic) {
                $sql = 'SELECT package_id, name FROM frs_package WHERE group_id 
= \''.$groupId.'\' ORDER BY name';
                
                if(!$showNonPublic) {
                        $sql .= ' AND is_public=1';
                }
                $sql .= ' ORDER BY name';
                
                $sections = array();
                $res = db_query($sql);
                while($data = db_fetch_array($res)) {
                        $sections[$data['package_id']] = $data['name'];
                }
                return $sections;
        }
}

?>
--- NEW FILE: TasksSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: TasksSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */

require_once('common/search/SearchQuery.class');

class TasksSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
        * flag if non public items are returned
        *
        * @var boolean $showNonPublic
        */      
        var $showNonPublic;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param array $sections sections to search in
         * @param boolean $showNonPublic flag if private sections are searched 
too
         */
        function TasksSearchQuery($words, $offset, $isExact, $groupId, 
$sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {  
                $this->groupId = $groupId;
                $this->showNonPublic = $showNonPublic;
                
                $this->SearchQuery($words, $offset, $isExact);
                                
                $this->setSections($sections);
        }

        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {
                $sql = 'SELECT 
project_task.project_task_id,project_task.summary,project_task.percent_complete,'
                        . ' 
project_task.start_date,project_task.end_date,users.firstname||\' 
\'||users.lastname AS realname, project_group_list.project_name, 
project_group_list.group_project_id ' 
                        . ' FROM project_task, users, project_group_list' 
                        . ' WHERE project_task.created_by = users.user_id'
                        . ' AND project_task.group_project_id = 
project_group_list.group_project_id '
                        . ' AND project_group_list.group_id  ='.$this->groupId;
                if ($this->sections != SEARCH__ALL_SECTIONS) {
                        $sql .= 'AND project_group_list.project_name in 
('.$this->sections.') ';
                }
                if (!$this->showNonPublic) {
                        $sql .= 'AND project_group_list.is_public = 1 ';
                }
                $sql .= 'AND(('.$this->getIlikeCondition('summary', 
$this->words).')' 
                        . ' OR ('.$this->getIlikeCondition('details', 
$this->words).'))' 
                        . ' ORDER BY project_group_list.project_name, 
project_task.project_task_id';
                return $sql;
        }
        
        /**
         * getSections - returns the list of available subprojects
         *
         * @param $groupId int group id
         * @param $showNonPublic boolean if we should consider non public 
sections
         */
        function getSections($groupId, $showNonPublic=false) {
                $sql = 'SELECT group_project_id, project_name FROM 
project_group_list WHERE group_id = '.$groupId.'';
                if (!$showNonPublic) {
                        $sql .= ' AND is_public = 1';
                }
                $sql .= ' ORDER BY project_name';
                
                $sections = array();
                $res = db_query($sql);
                while($data = db_fetch_array($res)) {
                        $sections[$data['group_project_id']] = 
$data['project_name'];
                }
                return $sections;
        }
}

?>
--- NEW FILE: DocsSearchQuery.class ---
<?php
/**
 * GForge Search Engine
 *
 * Copyright 2004 (c) Dominik Haas, GForge Team
 *
 * http://gforge.org
 *
 * @version $Id: DocsSearchQuery.class,v 1.1 2004/10/12 22:06:25 gsmet Exp $
 */

require_once('common/search/SearchQuery.class');

class DocsSearchQuery extends SearchQuery {
        
        /**
        * group id
        *
        * @var int $groupId
        */
        var $groupId;
        
        /**
        * flag if non public items are returned
        *
        * @var boolean $showNonPublic
        */      
        var $showNonPublic;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param array $sections sections to search in
         * @param boolean $showNonPublic flag if private sections are searched 
too
         */
        function DocsSearchQuery($words, $offset, $isExact, $groupId, 
$sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {   
                $this->groupId = $groupId;
                $this->showNonPublic = $showNonPublic;
                
                $this->SearchQuery($words, $offset, $isExact);
                
                $this->setSections($sections);
        }

        /**
         * getQuery - get the sql query built to get the search results
         *
         * @return string sql query to execute
         */
        function getQuery() {
                $sql = 'SELECT doc_data.docid, doc_data.title, 
doc_data.description, doc_groups.groupname'
                        .' FROM doc_data, doc_groups'
                        .' WHERE doc_data.doc_group = doc_groups.doc_group'
                        .' AND doc_data.group_id ='.$this->groupId;
                if ($this->sections != SEARCH__ALL_SECTIONS) {
                        $sql .= ' AND doc_groups.groupname IN 
('.$this->sections.') ';
                }
                if ($this->showNonPublic) {
                        $sql .= ' AND doc_data.stateid IN (1, 4, 5)';
                } else {
                        $sql .= ' AND doc_data.stateid = 1';
                }
                $sql .= ' AND (('.$this->getIlikeCondition('title', 
$this->words).')' 
                        .' OR ('.$this->getIlikeCondition('description', 
$this->words).'))'
                        .' ORDER BY doc_groups.groupname, doc_data.docid';
                return $sql;
        }
        
        /**
         * getSections - returns the list of available doc groups
         *
         * @param $groupId int group id
         * @param $showNonPublic boolean if we should consider non public 
sections
         */
        function getSections($groupId, $showNonPublic=false) {
                $sql = 'SELECT doc_groups.doc_group, doc_groups.groupname FROM 
doc_groups, doc_data'
                        .' WHERE doc_groups.doc_group = doc_data.doc_group AND 
doc_groups.group_id = '.$groupId;
                if ($showNonPublic) {
                        $sql .= ' AND doc_data.stateid IN (1, 4, 5)';
                } else {
                        $sql .= ' AND doc_data.stateid = 1';
                }
                $sql .= ' ORDER BY groupname';
                
                $sections = array();
                $res = db_query($sql);
                while($data = db_fetch_array($res)) {
                        $sections[$data['doc_group']] = $data['groupname'];
                }
                return $sections;
        }
}

?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]