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 ArtifactSearchQuery extends SearchQuery {
40 * @var int $artifactId
47 * @param string $words words we are searching for
48 * @param int $offset offset
49 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
50 * @param int $groupId group id
51 * @param int $artifactId artifact id
53 function ArtifactSearchQuery($words, $offset, $isExact, $groupId, $artifactId) {
54 //TODO: Why is groupId an arg and var since it isn't used anywhere?
55 $this->groupId = $groupId;
56 $this->artifactId = $artifactId;
58 $this->SearchQuery($words, $offset, $isExact);
62 * getQuery - get the query built to get the search results
64 * @return array query+params array
67 global $sys_database_type;
70 $qpa = db_construct_qpa () ;
73 $words=$this->getFormattedWords();
74 $artifactId = $this->artifactId;
77 $qpa = db_construct_qpa ($qpa,
78 'SELECT a.group_artifact_id, a.artifact_id, headline(summary, $1) AS summary, ',
79 array ($this->getFormattedWords())) ;
80 $qpa = db_construct_qpa ($qpa,
81 'a.open_date, users.realname, rank FROM (SELECT a.artifact_id, SUM (RANK(ai.vectors, q) + RANK(ami.vectors, q)) AS rank FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id)') ;
83 $qpa = db_construct_qpa ($qpa,
84 ', artifact_idx ai, artifact_message_idx ami, to_tsquery($1) q',
86 $qpa = db_construct_qpa ($qpa,
87 'WHERE a.group_artifact_id=$1',
88 array ($artifactId)) ;
89 $qpa = db_construct_qpa ($qpa,
90 ' AND ai.artifact_id = a.artifact_id AND ami.id = am.id AND ((ai.vectors @@ q OR ami.vectors @@ q) ') ;
92 if (count($this->phrases)) {
93 $qpa = db_construct_qpa ($qpa,
94 $this->getOperator()) ;
95 $qpa = db_construct_qpa ($qpa,
97 $qpa = $this->addMatchCondition($qpa, 'a.details');
98 $qpa = db_construct_qpa ($qpa,
100 $qpa = $this->addMatchCondition($qpa, 'a.summary');
101 $qpa = db_construct_qpa ($qpa,
103 $qpa = $this->addMatchCondition($qpa, 'am.body');
104 $qpa = db_construct_qpa ($qpa,
107 $qpa = db_construct_qpa ($qpa,
108 ') GROUP BY a.artifact_id) x, artifact a, users WHERE a.artifact_id=x.artifact_id AND users.user_id=a.submitted_by ORDER BY group_artifact_id ASC, rank DESC, a.artifact_id ASC') ;
110 $qpa = db_construct_qpa ($qpa,
111 'SELECT a.group_artifact_id, a.artifact_id, summary, a.open_date, users.realname, rank FROM (SELECT a.artifact_id, 0 AS rank FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id)') ;
113 $qpa = db_construct_qpa ($qpa,
114 'WHERE a.group_artifact_id=$1',
115 array ($artifactId)) ;
117 if (count($this->phrases)) {
118 $qpa = db_construct_qpa ($qpa,
120 $qpa = db_construct_qpa ($qpa,
122 $qpa = $this->addMatchCondition($qpa, 'a.details');
123 $qpa = db_construct_qpa ($qpa,
125 $qpa = $this->addMatchCondition($qpa, 'a.summary');
126 $qpa = db_construct_qpa ($qpa,
128 $qpa = $this->addMatchCondition($qpa, 'am.body');
129 $qpa = db_construct_qpa ($qpa,
132 $qpa = db_construct_qpa ($qpa,
133 ' GROUP BY a.artifact_id) x, artifact a, users WHERE a.artifact_id=x.artifact_id AND users.user_id=a.submitted_by ORDER BY group_artifact_id ASC, rank DESC, a.artifact_id ASC') ;
136 $qpa = db_construct_qpa ($qpa,
137 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id,a.artifact_id,a.summary,a.open_date,users.realname ') ;
138 $qpa = db_construct_qpa ($qpa,
139 'FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id), users WHERE a.group_artifact_id=$1 AND users.user_id=a.submitted_by AND ((',
140 array ($this->artifactId)) ;
142 $qpa = $this->addIlikeCondition ($qpa, 'a.details') ;
143 $qpa = db_construct_qpa ($qpa,
145 $qpa = $this->addIlikeCondition ($qpa, 'a.summary') ;
146 $qpa = db_construct_qpa ($qpa,
148 $qpa = $this->addIlikeCondition ($qpa, 'am.body') ;
149 $qpa = db_construct_qpa ($qpa,
150 ')) ORDER BY group_artifact_id ASC, a.artifact_id ASC') ;
156 * getSearchByIdQuery - get the query built to get the search results when we are looking for an int
158 * @return array query+params array
160 function getSearchByIdQuery() {
161 global $sys_database_type;
163 $qpa = db_construct_qpa () ;
165 $qpa = db_construct_qpa ($qpa,
166 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id, a.artifact_id') ;
167 $qpa = db_construct_qpa ($qpa,
168 ' FROM artifact a WHERE a.group_artifact_id=$1 AND a.artifact_id=$2',
169 array ($this->artifactId,
178 // c-file-style: "bsd"