3 * FusionForge search engine
5 * Copyright 1999-2001, VA Linux Systems, Inc
6 * Copyright 2004, Guillaume Smet/Open Wide
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
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 ArtifactSearchQuery extends SearchQuery {
39 * @var int $artifactId
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 int $artifactId artifact id
52 function __construct($words, $offset, $isExact, $groupId, $artifactId) {
53 //TODO: Why is groupId an arg and var since it isn't used anywhere?
54 $this->groupId = $groupId;
55 $this->artifactId = $artifactId;
57 parent::__construct($words, $offset, $isExact);
61 * getQuery - get the query built to get the search results
63 * @return array query+params array
66 $qpa = db_construct_qpa () ;
68 if (forge_get_config('use_fti')) {
69 $words = $this->getFTIwords();
71 if (count($this->phrases)) {
72 $qpa = db_construct_qpa ($qpa,
73 'SELECT x.* FROM (SELECT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact.summary||$1||artifact.details||$1||coalesce(ff_string_agg(artifact_message.body), $1) as full_string_agg, artifact_idx.vectors FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users, artifact_idx WHERE users.user_id = artifact.submitted_by AND artifact.group_artifact_id = $2 AND artifact.artifact_id = artifact_idx.artifact_id AND vectors @@ to_tsquery($3) GROUP BY artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact.details, vectors) AS x WHERE ',
74 array ($this->field_separator, $this->artifactId, $words)) ;
75 $qpa = $this->addMatchCondition ($qpa, 'full_string_agg') ;
76 $qpa = db_construct_qpa ($qpa,
77 ' ORDER BY ts_rank(vectors, to_tsquery($1)) DESC',
80 $qpa = db_construct_qpa ($qpa,
81 'SELECT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_idx.vectors FROM artifact, users, artifact_idx WHERE users.user_id = artifact.submitted_by AND artifact.group_artifact_id = $1 AND artifact.artifact_id = artifact_idx.artifact_id AND vectors @@ to_tsquery($2) ORDER BY ts_rank(vectors, to_tsquery($2)) DESC',
82 array ($this->artifactId, $words)) ;
86 $qpa = db_construct_qpa ($qpa,
87 'SELECT x.* FROM (SELECT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact.summary||$1||artifact.details||$1||coalesce(ff_string_agg(artifact_message.body), $1) as full_string_agg FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users WHERE users.user_id = artifact.submitted_by AND artifact.group_artifact_id = $2 GROUP BY artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact.details) AS x WHERE ',
88 array ($this->field_separator, $this->artifactId)) ;
89 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
90 $qpa = db_construct_qpa ($qpa,
91 ' ORDER BY artifact_id') ;
100 // c-file-style: "bsd"