3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 require_once $gfcommon.'search/SearchQuery.class.php';
27 class ForumsSearchQuery extends SearchQuery {
37 * flag if non public items are returned
39 * @var boolean $showNonPublic
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 array $sections sections to search in
51 * @param boolean $showNonPublic flag if private sections are searched too
53 function ForumsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
54 $this->groupId = $groupId;
55 $this->showNonPublic = $showNonPublic;
57 $this->SearchQuery($words, $offset, $isExact);
59 $this->setSections($sections);
63 * getQuery - get the sql query built to get the search results
65 * @return string sql query to execute
72 if ($this->showNonPublic) {
75 if ($this->sections != SEARCH__ALL_SECTIONS) {
76 $sections = $this->sections;
78 $sql = 'SELECT forum.msg_id, headline(forum.subject, q) AS subject, forum.post_date, users.realname, forum_group_list.forum_name '
79 . 'FROM forum, users, forum_group_list, forum_idx, to_tsquery(\''.
80 $this->getFormattedWords().'\') as q '
81 . 'WHERE users.user_id = forum.posted_by '
82 . 'AND vectors @@ q AND forum.msg_id = forum_idx.msg_id '
83 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
84 . 'AND forum_group_list.is_public <> 9 '
85 . 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
86 if ($this->sections != SEARCH__ALL_SECTIONS) {
87 $sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
89 if (!$this->showNonPublic) {
90 $sql .= 'AND forum_group_list.is_public = 1 ';
92 $sql .= 'ORDER BY forum_group_list.forum_name ASC, forum.msg_id ASC, rank(vectors, q) DESC';
94 $sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname, forum_group_list.forum_name '
95 . 'FROM forum, users, forum_group_list '
96 . 'WHERE users.user_id = forum.posted_by '
97 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
98 . 'AND forum_group_list.is_public <> 9 '
99 . 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
100 if ($this->sections != SEARCH__ALL_SECTIONS) {
101 $sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
103 if (!$this->showNonPublic) {
104 $sql .= 'AND forum_group_list.is_public = 1 ';
106 $sql .= 'AND (('.$this->getIlikeCondition('forum.body', $this->words).') '
107 . 'OR ('.$this->getIlikeCondition('forum.subject', $this->words).')) '
108 . 'ORDER BY forum_group_list.forum_name, forum.msg_id';
114 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
116 * @return string sql query to execute
118 function getSearchByIdQuery() {
119 $sql = 'SELECT msg_id '
120 . 'FROM forum, forum_group_list '
121 . 'WHERE msg_id=\''.$this->searchId.'\' '
122 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
123 . 'AND group_forum_id=\''.$this->forumId.'\'';
124 if (!$this->showNonPublic) {
125 $sql .= ' AND forum_group_list.is_public = 1';
132 * getSections - returns the list of available forums
134 * @param $groupId int group id
135 * @param $showNonPublic boolean if we should consider non public sections
137 function getSections($groupId, $showNonPublic=false) {
138 $sql = 'SELECT group_forum_id, forum_name FROM forum_group_list WHERE group_id = '.$groupId.' AND is_public <> 9';
139 if (!$showNonPublic) {
140 $sql .= ' AND is_public = 1';
142 $sql .= ' ORDER BY forum_name';
145 $res = db_query($sql);
146 while($data = db_fetch_array($res)) {
147 $sections[$data['group_forum_id']] = $data['forum_name'];
155 // c-file-style: "bsd"