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 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfcommon.'search/SearchQuery.class.php';
29 class ProjectSearchQuery extends SearchQuery {
32 * getQuery - get the query built to get the search results
34 * @return array query+params array
37 $qpa = db_construct_qpa () ;
39 if (forge_get_config('use_fti')) {
40 $words = $this->getFTIwords();
41 $qpa = db_construct_qpa ($qpa,
42 '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) ',
46 $qpa = db_construct_qpa ($qpa,
47 'AND vectors @@ q ') ;
48 if (count($this->phrases)) {
49 $qpa = db_construct_qpa ($qpa,
51 $qpa = $this->addMatchCondition($qpa, 'group_name');
52 $qpa = db_construct_qpa ($qpa,
54 $qpa = $this->addMatchCondition($qpa, 'short_description');
55 $qpa = db_construct_qpa ($qpa,
57 $qpa = $this->addMatchCondition($qpa, 'unix_group_name');
58 $qpa = db_construct_qpa ($qpa,
61 $qpa = db_construct_qpa ($qpa,
62 'AND g.group_id = i.group_id ORDER BY ts_rank(vectors, q) DESC, group_name') ;
64 $qpa = db_construct_qpa ($qpa,
65 '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 ((',
67 $qpa = $this->addIlikeCondition ($qpa, 'g.group_name') ;
68 $qpa = db_construct_qpa ($qpa,
70 $qpa = $this->addIlikeCondition ($qpa, 'g.short_description') ;
71 $qpa = db_construct_qpa ($qpa,
73 $qpa = $this->addIlikeCondition ($qpa, 'g.unix_group_name') ;
74 $qpa = db_construct_qpa ($qpa,
75 ')) ORDER BY g.group_name') ;
84 // c-file-style: "bsd"