6 * Portions Copyright 1999-2001 (c) VA Linux Systems
7 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
14 require_once('common/search/SearchQuery.class');
16 class ProjectSearchQuery extends SearchQuery {
21 * @param string $words words we are searching for
22 * @param int $offset offset
23 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
25 function ProjectSearchQuery($words, $offset, $isExact) {
26 $this->SearchQuery($words, $offset, $isExact);
30 * getQuery - get the sql query built to get the search results
32 * @return string sql query to execute
37 if(count($this->words)) {
38 $tsquery0 = "headline(group_name, q) as group_name, " .
40 "headline(short_description, q) as short_description";
41 $words = $this->getFormattedWords();
42 $tsquery = ", to_tsquery('$words') AS q, groups_idx as i ";
43 $tsmatch = "vectors @@ q";
45 $tsjoin = 'AND g.group_id = i.group_id';
46 $distinctOn = "rank(vectors, q), group_name";
47 $orderBy = "ORDER BY rank(vectors, q) DESC, group_name";
48 $phraseOp = $this->getOperator();
50 $tsquery0 = "group_name, unix_group_name, short_description";
55 $distinctOn = "group_name";
56 $orderBy = "ORDER BY group_name";
60 if(count($this->phrases)) {
61 $groupNameCond = $this->getMatchCond('group_name', $this->phrases);
62 $groupDescriptionCond = $this->getMatchCond('short_description', $this->phrases);
63 $groupUnixNameCond = $this->getMatchCond('unix_group_name', $this->phrases);
64 $phraseCond = $phraseOp.' (('.$groupNameCond.') OR ('.$groupDescriptionCond.') OR ('.$groupUnixNameCond.'))';
66 $sql = "SELECT DISTINCT ON ($distinctOn) type_id, g.group_id, " .$tsquery0.
67 " FROM groups AS g ".$tsquery.
68 " WHERE g.status in ('A', 'H') AND ($tsmatch $phraseCond) $tsjoin $orderBy";
70 $groupNameCond = $this->getIlikeCondition('group_name', $this->words);
71 $groupDescriptionCond = $this->getIlikeCondition('short_description', $this->words);
72 $groupUnixNameCond = $this->getIlikeCondition('unix_group_name', $this->words);
74 $sql = 'SELECT group_name, unix_group_name, type_id, group_id, short_description '
76 .'WHERE status IN (\'A\', \'H\') '
77 .'AND is_public=\'1\' '
78 .'AND (('.$groupNameCond.') OR ('.$groupDescriptionCond.') OR ('.$groupUnixNameCond.'))';