1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<?php
/**
* GForge Search Engine
*
* Portions Copyright 1999-2001 (c) VA Linux Systems
* The rest Copyright 2004 (c) Guillaume Smet / Open Wide
*
* http://gforge.org
*
* @version $Id: ArtifactSearchQuery.class 5270 2006-02-05 17:12:19Z tperdue $
*/
require_once('common/search/SearchQuery.class');
class ArtifactSearchQuery extends SearchQuery {
/**
* group id
*
* @var int $groupId
*/
var $groupId;
/**
* artifact id
*
* @var int $artifactId
*/
var $artifactId;
/**
* Constructor
*
* @param string $words words we are searching for
* @param int $offset offset
* @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
* @param int $groupId group id
* @param int $artifactId artifact id
*/
function ArtifactSearchQuery($words, $offset, $isExact, $groupId, $artifactId) {
$this->groupId = $groupId;
$this->artifactId = $artifactId;
$this->SearchQuery($words, $offset, $isExact);
}
/**
* getQuery - get the sql query built to get the search results
*
* @return string sql query to execute
*/
function getQuery() {
global $sys_use_fti;
if ($sys_use_fti) {
$words=$this->getFormattedWords();
$artifactId = $this->artifactId;
$sql = "SELECT DISTINCT ON (artifact.artifact_id) artifact.artifact_id,
artifact.group_artifact_id, artifact.summary AS summary,
artifact.open_date, users.realname, artifact_group_list.name
FROM artifact LEFT JOIN artifact_message USING (artifact_id), users,
artifact_group_list
WHERE users.user_id = artifact.submitted_by
AND artifact_group_list.group_artifact_id = artifact.group_artifact_id
AND artifact_group_list.group_artifact_id='$artifactId'
AND artifact.artifact_id IN (
SELECT artifact_id FROM artifact_idx,
to_tsquery('$words') AS q WHERE vectors @@ q ORDER BY rank(vectors, q) DESC)
OR artifact.artifact_id IN (
SELECT artifact_id FROM artifact_message_idx,
to_tsquery('$words') AS q WHERE vectors @@ q ORDER BY rank(vectors, q) DESC)";
} else {
$sql = 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id,a.artifact_id,a.summary,a.open_date,users.realname '
. 'FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id), users '
. 'WHERE a.group_artifact_id=\''.$this->artifactId.'\' '
. 'AND users.user_id=a.submitted_by '
. 'AND (('.$this->getIlikeCondition('a.details', $this->words).') '
. 'OR ('.$this->getIlikeCondition('a.summary', $this->words).') '
. 'OR ('.$this->getIlikeCondition('am.body', $this->words).')) '
. 'ORDER BY group_artifact_id ASC, a.artifact_id ASC';
}
return $sql;
}
/**
* getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
*
* @return string sql query to execute
*/
function getSearchByIdQuery() {
$sql = 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id, a.artifact_id '
. 'FROM artifact a '
. 'WHERE a.group_artifact_id=\''.$this->artifactId.'\' '
. 'AND a.artifact_id=\''.$this->searchId.'\'';
return $sql;
}
}
?>
|