3 * FusionForge search engine
5 * Copyright 1999-2001, VA Linux Systems, Inc
6 * Copyright 2004, Guillaume Smet/Open Wide
7 * Copyright 2010, Roland Mas
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
47 $qpa = db_construct_qpa () ;
49 if (forge_get_config('use_fti')) {
50 $words = $this->getFTIwords();
51 $qpa = db_construct_qpa ($qpa,
52 'SELECT DISTINCT ON (ts_rank(vectors, q), group_name) type_id, g.group_id, ts_headline(group_name, q) as group_name, unix_group_name, ts_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) ',
56 $qpa = db_construct_qpa ($qpa,
57 'AND vectors @@ q ') ;
58 if (count($this->phrases)) {
59 $qpa = db_construct_qpa ($qpa,
61 $qpa = $this->addMatchCondition($qpa, 'group_name');
62 $qpa = db_construct_qpa ($qpa,
64 $qpa = $this->addMatchCondition($qpa, 'short_description');
65 $qpa = db_construct_qpa ($qpa,
67 $qpa = $this->addMatchCondition($qpa, 'unix_group_name');
68 $qpa = db_construct_qpa ($qpa,
71 $qpa = db_construct_qpa ($qpa,
72 'AND g.group_id = i.group_id ORDER BY ts_rank(vectors, q) DESC, group_name') ;
74 $qpa = db_construct_qpa ($qpa,
75 '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 ((',
77 $qpa = $this->addIlikeCondition ($qpa, 'g.group_name') ;
78 $qpa = db_construct_qpa ($qpa,
80 $qpa = $this->addIlikeCondition ($qpa, 'g.short_description') ;
81 $qpa = db_construct_qpa ($qpa,
83 $qpa = $this->addIlikeCondition ($qpa, 'g.unix_group_name') ;
84 $qpa = db_construct_qpa ($qpa,
85 ')) ORDER BY g.group_name') ;
94 // c-file-style: "bsd"