3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'search/SearchQuery.class.php';
27 class TasksSearchQuery extends SearchQuery {
37 * flag if non public items are returned
39 * @var boolean $showNonPublic
46 * @param string $words words we are searching for
47 * @param int $offset offset
48 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
49 * @param int $groupId group id
50 * @param array $sections sections to search in
51 * @param boolean $showNonPublic flag if private sections are searched too
53 function TasksSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
54 $this->groupId = $groupId;
55 $this->showNonPublic = $showNonPublic;
57 $this->SearchQuery($words, $offset, $isExact);
59 $this->setSections($sections);
63 * getQuery - get the query built to get the search results
65 * @return array query+params array
68 $qpa = db_construct_qpa () ;
70 $qpa = db_construct_qpa ($qpa,
71 'SELECT x.* FROM (SELECT y.group_project_id, y.project_task_id, y.summary, y.percent_complete, y.start_date, y.end_date, users.realname, project_group_list.project_name, y.full_string_agg',
73 if (forge_get_config('use_fti')) {
74 $words = $this->getFTIwords();
75 $qpa = db_construct_qpa ($qpa,
76 ', y.full_vector_agg',
79 $qpa = db_construct_qpa ($qpa,
80 ' FROM (SELECT project_task.project_task_id, project_task.summary, project_task.percent_complete, project_task.start_date, project_task.end_date, project_task.created_by, project_task.group_project_id, project_task.summary||$1||project_task.details||$1||coalesce(ff_string_agg(project_messages.body), $1) as full_string_agg',
81 array($this->field_separator));
82 if (forge_get_config('use_fti')) {
83 $qpa = db_construct_qpa ($qpa,
84 ', project_task_idx.vectors || coalesce(ff_tsvector_agg(project_messages_idx.vectors), to_tsvector($1)) AS full_vector_agg',
87 $qpa = db_construct_qpa ($qpa,
88 ' FROM project_task LEFT OUTER JOIN project_messages USING (project_task_id)',
91 if (forge_get_config('use_fti')) {
92 $qpa = db_construct_qpa ($qpa,
93 ' LEFT OUTER JOIN project_messages_idx ON (project_messages.project_message_id = project_messages_idx.id) JOIN project_task_idx ON (project_task.project_task_id = project_task_idx.project_task_id)',
96 $qpa = db_construct_qpa ($qpa,
97 ' GROUP BY project_task.project_task_id, project_task.summary, project_task.details, project_task.percent_complete, project_task.start_date, project_task.end_date, project_task.created_by, project_task.group_project_id',
100 if (forge_get_config('use_fti')) {
101 $qpa = db_construct_qpa ($qpa,
102 ', project_task_idx.vectors',
105 $qpa = db_construct_qpa ($qpa,
106 ') AS y, users, project_group_list',
109 if (forge_get_config('use_fti')) {
110 $qpa = db_construct_qpa ($qpa,
111 ', project_task_idx',
114 $qpa = db_construct_qpa ($qpa,
115 ' WHERE y.created_by = users.user_id AND y.group_project_id = project_group_list.group_project_id AND project_group_list.group_id = $1',
116 array($this->groupId));
117 if ($this->sections != SEARCH__ALL_SECTIONS) {
118 $qpa = db_construct_qpa ($qpa,
119 ' AND y.group_project_id = ANY ($1)',
120 array (db_int_array_to_any_clause ($this->sections))) ;
122 if (!$this->showNonPublic) {
123 $qpa = db_construct_qpa ($qpa,
124 ' AND project_group_list.is_public = 1') ;
126 $qpa = db_construct_qpa ($qpa,
127 ' GROUP BY y.group_project_id, y.project_task_id, y.summary, y.percent_complete, y.start_date, y.end_date, users.realname, project_group_list.project_name, y.full_string_agg',
130 if (forge_get_config('use_fti')) {
131 $qpa = db_construct_qpa ($qpa,
132 ', y.full_vector_agg',
135 $qpa = db_construct_qpa ($qpa,
139 if (forge_get_config('use_fti')) {
140 $qpa = db_construct_qpa ($qpa,
141 'full_vector_agg @@ to_tsquery($1) ',
143 if (count($this->phrases)) {
144 $qpa = db_construct_qpa ($qpa,
146 $qpa = $this->addMatchCondition ($qpa, 'x.full_string_agg') ;
147 $qpa = db_construct_qpa ($qpa,
150 $qpa = db_construct_qpa ($qpa,
151 'ORDER BY ts_rank(full_vector_agg, to_tsquery($1)) DESC',
155 $qpa = $this->addIlikeCondition ($qpa, 'x.full_string_agg') ;
156 $qpa = db_construct_qpa ($qpa,
157 ' ORDER BY x.project_name, x.project_task_id') ;
164 * getSections - returns the list of available subprojects
166 * @param $groupId int group id
167 * @param $showNonPublic boolean if we should consider non public sections
169 static function getSections($groupId, $showNonPublic=false) {
170 $sql = 'SELECT group_project_id, project_name FROM project_group_list WHERE group_id=$1' ;
171 $sql .= ' ORDER BY project_name';
174 $res = db_query_params ($sql,
176 while($data = db_fetch_array($res)) {
177 if (forge_check_perm('pm',$data['group_project_id'],'read')) {
178 $sections[$data['group_project_id']] = $data['project_name'];
187 // c-file-style: "bsd"