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 project_task.project_task_id, project_task.summary, project_task.percent_complete, project_task.start_date, project_task.end_date, users.realname, project_group_list.project_name, project_task.summary||$1||project_task.details||$1||coalesce(ff_string_agg(project_messages.body), $1) as full_string_agg',
73 if (forge_get_config('use_fti')) {
74 $words = $this->getFTIwords();
75 $qpa = db_construct_qpa ($qpa,
76 ', (project_task_idx.vectors || coalesce(ff_tsvector_agg(project_messages_idx.vectors), $1::tsvector)) AS full_vector_agg',
79 $qpa = db_construct_qpa ($qpa,
80 ' FROM project_task LEFT OUTER JOIN project_messages USING (project_task_id), users, project_group_list',
82 if (forge_get_config('use_fti')) {
83 $qpa = db_construct_qpa ($qpa,
84 ', project_task_idx, project_messages_idx',
87 $qpa = db_construct_qpa ($qpa,
88 ' 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 = $1 AND project_messages.project_task_id = project_task.project_task_id ',
89 array ($this->groupId)) ;
90 if ($this->sections != SEARCH__ALL_SECTIONS) {
91 $qpa = db_construct_qpa ($qpa,
92 'AND project_group_list.group_project_id = ANY ($1) ',
93 array (db_int_array_to_any_clause ($this->sections))) ;
95 if (!$this->showNonPublic) {
96 $qpa = db_construct_qpa ($qpa,
97 'AND project_group_list.is_public = 1 ') ;
100 if (forge_get_config('use_fti')) {
101 $qpa = db_construct_qpa ($qpa,
102 'AND project_task.project_task_id = project_task_idx.project_task_id AND project_messages.project_message_id = project_messages_idx.id ',
105 $qpa = db_construct_qpa ($qpa,
106 'GROUP BY project_task.project_task_id, project_task.summary, project_task.percent_complete, project_task.start_date, project_task.end_date, users.realname, project_group_list.project_name, project_task.details') ;
107 if (forge_get_config('use_fti')) {
108 $qpa = db_construct_qpa ($qpa,
109 ', project_task_idx.vectors',
112 $qpa = db_construct_qpa ($qpa,
115 if (forge_get_config('use_fti')) {
116 $qpa = db_construct_qpa ($qpa,
117 'full_vector_agg @@ $1 ',
119 if (count($this->phrases)) {
120 $qpa = db_construct_qpa ($qpa,
122 $qpa = $this->addMatchCondition ($qpa, 'x.full_string_agg') ;
123 $qpa = db_construct_qpa ($qpa,
126 $qpa = db_construct_qpa ($qpa,
127 'ORDER BY ts_rank(full_vector_agg, $1) DESC',
131 $qpa = $this->addIlikeCondition ($qpa, 'x.full_string_agg') ;
132 $qpa = db_construct_qpa ($qpa,
133 ' ORDER BY x.project_name, x.project_task_id') ;
139 * getSections - returns the list of available subprojects
141 * @param $groupId int group id
142 * @param $showNonPublic boolean if we should consider non public sections
144 static function getSections($groupId, $showNonPublic=false) {
145 $sql = 'SELECT group_project_id, project_name FROM project_group_list WHERE group_id=$1' ;
146 if (!$showNonPublic) {
147 $sql .= ' AND is_public = 1';
149 $sql .= ' ORDER BY project_name';
152 $res = db_query_params ($sql,
154 while($data = db_fetch_array($res)) {
155 $sections[$data['group_project_id']] = $data['project_name'];
163 // c-file-style: "bsd"