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 ProjectSearchQuery extends SearchQuery {
33 * @param string $words words we are searching for
34 * @param int $offset offset
35 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
37 function ProjectSearchQuery($words, $offset, $isExact) {
38 $this->SearchQuery($words, $offset, $isExact);
42 * getQuery - get the sql query built to get the search results
44 * @return string sql query to execute
49 if(count($this->words)) {
50 $tsquery0 = "headline(group_name, q) as group_name, " .
52 "headline(short_description, q) as short_description";
53 $words = $this->getFormattedWords();
54 $tsquery = ", to_tsquery('$words') AS q, groups_idx as i ";
55 $tsmatch = "vectors @@ q";
57 $tsjoin = 'AND g.group_id = i.group_id';
58 $distinctOn = "rank(vectors, q), group_name";
59 $orderBy = "ORDER BY rank(vectors, q) DESC, group_name";
60 $phraseOp = $this->getOperator();
62 $tsquery0 = "group_name, unix_group_name, short_description";
67 $distinctOn = "group_name";
68 $orderBy = "ORDER BY group_name";
72 if(count($this->phrases)) {
73 $groupNameCond = $this->getMatchCond('group_name', $this->phrases);
74 $groupDescriptionCond = $this->getMatchCond('short_description', $this->phrases);
75 $groupUnixNameCond = $this->getMatchCond('unix_group_name', $this->phrases);
76 $phraseCond = $phraseOp.' (('.$groupNameCond.') OR ('.$groupDescriptionCond.') OR ('.$groupUnixNameCond.'))';
78 $sql = "SELECT DISTINCT ON ($distinctOn) type_id, g.group_id, " .$tsquery0.
79 " FROM groups AS g ".$tsquery.
80 " WHERE g.status in ('A', 'H') AND ($tsmatch $phraseCond) $tsjoin $orderBy";
82 $groupNameCond = $this->getIlikeCondition('group_name', $this->words);
83 $groupDescriptionCond = $this->getIlikeCondition('short_description', $this->words);
84 $groupUnixNameCond = $this->getIlikeCondition('unix_group_name', $this->words);
86 $sql = 'SELECT group_name, unix_group_name, type_id, group_id, short_description '
88 .'WHERE status IN (\'A\', \'H\') '
89 .'AND is_public=\'1\' '
90 .'AND (('.$groupNameCond.') OR ('.$groupDescriptionCond.') OR ('.$groupUnixNameCond.'))';
99 // c-file-style: "bsd"