3 * FusionForge search engine
5 * Copyright 1999-2001, VA Linux Systems, Inc
6 * Copyright 2004, Guillaume Smet/Open Wide
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'search/SearchQuery.class.php';
28 class ProjectSearchQuery extends SearchQuery {
33 * @param string $words words we are searching for
34 * @param int $offset offset
35 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
37 function ProjectSearchQuery($words, $offset, $isExact) {
38 $this->SearchQuery($words, $offset, $isExact);
42 * getQuery - get the query built to get the search results
44 * @return array query+params array
49 $qpa = db_construct_qpa () ;
51 if (forge_get_config('use_fti')) {
52 if (count ($this->words)) {
53 $words = $this->getFormattedWords();
54 $qpa = db_construct_qpa ($qpa,
55 'SELECT DISTINCT ON (rank(vectors, q), group_name) type_id, g.group_id, headline(group_name, q) as group_name, unix_group_name, headline(short_description, q) as short_description FROM groups AS g, to_tsquery($1) AS q, groups_idx as i WHERE g.status in ($2, $3) AND (g.is_public=1 ',
61 $qpa = db_construct_qpa ($qpa,
62 'OR g.group_id in (SELECT ug.group_id FROM user_group ug WHERE ug.user_id = $1 AND ug.group_id = g.group_id) ',
63 array ($LUSER->getID())) ;
65 $qpa = db_construct_qpa ($qpa,
66 ') AND (vectors @@ q AND ') ;
68 $qpa = db_construct_qpa ($qpa,
69 'SELECT DISTINCT ON (group_name) type_id, g.group_id, group_name, unix_group_name, short_description FROM groups AS g WHERE g.status in ($1, $2) AND (g.is_public=1 ',
73 $qpa = db_construct_qpa ($qpa,
74 'OR g.group_id in (SELECT ug.group_id FROM user_group ug WHERE ug.user_id = $1 AND ug.group_id = g.group_id) ',
75 array ($LUSER->getID())) ;
77 $qpa = db_construct_qpa ($qpa,
81 if (count($this->phrases)) {
82 $qpa = db_construct_qpa ($qpa,
84 $qpa = $this->addMatchCondition($qpa, 'group_name');
85 $qpa = db_construct_qpa ($qpa,
87 $qpa = $this->addMatchCondition($qpa, 'short_description');
88 $qpa = db_construct_qpa ($qpa,
90 $qpa = $this->addMatchCondition($qpa, 'unix_group_name');
91 $qpa = db_construct_qpa ($qpa,
94 $qpa = db_construct_qpa ($qpa,
96 if (count ($this->words)) {
97 $qpa = db_construct_qpa ($qpa,
98 'AND g.group_id = i.group_id ORDER BY rank(vectors, q) DESC, group_name') ;
100 $qpa = db_construct_qpa ($qpa,
101 'ORDER BY group_name') ;
104 $qpa = db_construct_qpa ($qpa,
105 'SELECT g.group_name AS group_name, g.unix_group_name AS unix_group_name, g.type_id AS type_id, g.group_id AS group_id, g.short_description AS short_description FROM groups g WHERE g.status IN ($1, $2) AND (g.is_public=1 ',
107 if (isset ($LUSER)) {
108 $qpa = db_construct_qpa ($qpa,
109 'OR g.group_id in (SELECT ug.group_id FROM user_group ug WHERE ug.user_id = $1 AND ug.group_id = g.group_id) ',
110 array($LUSER->getID())) ;
112 $qpa = db_construct_qpa ($qpa,
114 $qpa = $this->addIlikeCondition ($qpa, 'g.group_name') ;
115 $qpa = db_construct_qpa ($qpa,
117 $qpa = $this->addIlikeCondition ($qpa, 'g.short_description') ;
118 $qpa = db_construct_qpa ($qpa,
120 $qpa = $this->addIlikeCondition ($qpa, 'g.unix_group_name') ;
121 $qpa = db_construct_qpa ($qpa,
122 ')) ORDER BY g.group_name') ;
131 // c-file-style: "bsd"