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. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'search/SearchQuery.class.php';
26 class ArtifactSearchQuery extends SearchQuery {
38 * @var int $artifactId
45 * @param string $words words we are searching for
46 * @param int $offset offset
47 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
48 * @param int $groupId group id
49 * @param int $artifactId artifact id
51 function ArtifactSearchQuery($words, $offset, $isExact, $groupId, $artifactId) {
52 //TODO: Why is groupId an arg and var since it isn't used anywhere?
53 $this->groupId = $groupId;
54 $this->artifactId = $artifactId;
56 $this->SearchQuery($words, $offset, $isExact);
60 * getQuery - get the query built to get the search results
62 * @return array query+params array
65 $qpa = db_construct_qpa () ;
67 if (forge_get_config('use_fti')) {
68 $words=$this->getFTIwords();
69 $artifactId = $this->artifactId;
71 $qpa = db_construct_qpa ($qpa,
72 'SELECT a.group_artifact_id, a.artifact_id, ts_headline(summary, $1) AS summary, ',
74 $qpa = db_construct_qpa ($qpa,
75 'a.open_date, users.realname, rank FROM (SELECT a.artifact_id, SUM (ts_rank(ai.vectors, q) + ts_rank(ami.vectors, q)) AS rank FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id)') ;
77 $qpa = db_construct_qpa ($qpa,
78 ', artifact_idx ai, artifact_message_idx ami, to_tsquery($1) q',
80 $qpa = db_construct_qpa ($qpa,
81 'WHERE a.group_artifact_id=$1',
82 array ($artifactId)) ;
83 $qpa = db_construct_qpa ($qpa,
84 ' AND ai.artifact_id = a.artifact_id AND ami.id = am.id AND ((ai.vectors @@ q OR ami.vectors @@ q) ') ;
86 if (count($this->phrases)) {
87 $qpa = db_construct_qpa ($qpa,
88 $this->getOperator()) ;
89 $qpa = db_construct_qpa ($qpa,
91 $qpa = $this->addMatchCondition($qpa, 'a.details');
92 $qpa = db_construct_qpa ($qpa,
94 $qpa = $this->addMatchCondition($qpa, 'a.summary');
95 $qpa = db_construct_qpa ($qpa,
97 $qpa = $this->addMatchCondition($qpa, 'am.body');
98 $qpa = db_construct_qpa ($qpa,
101 $qpa = db_construct_qpa ($qpa,
102 ') 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') ;
104 $qpa = db_construct_qpa ($qpa,
105 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id,a.artifact_id,a.summary,a.open_date,users.realname ') ;
106 $qpa = db_construct_qpa ($qpa,
107 '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 ((',
108 array ($this->artifactId)) ;
110 $qpa = $this->addIlikeCondition ($qpa, 'a.details') ;
111 $qpa = db_construct_qpa ($qpa,
113 $qpa = $this->addIlikeCondition ($qpa, 'a.summary') ;
114 $qpa = db_construct_qpa ($qpa,
116 $qpa = $this->addIlikeCondition ($qpa, 'am.body') ;
117 $qpa = db_construct_qpa ($qpa,
118 ')) ORDER BY group_artifact_id ASC, a.artifact_id ASC') ;
124 * getSearchByIdQuery - get the query built to get the search results when we are looking for an int
126 * @return array query+params array
128 function getSearchByIdQuery() {
129 $qpa = db_construct_qpa () ;
131 $qpa = db_construct_qpa ($qpa,
132 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id, a.artifact_id') ;
133 $qpa = db_construct_qpa ($qpa,
134 ' FROM artifact a WHERE a.group_artifact_id=$1 AND a.artifact_id=$2',
135 array ($this->artifactId,
144 // c-file-style: "bsd"