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 ForumSearchQuery extends SearchQuery {
47 * @param string $words words we are searching for
48 * @param int $offset offset
49 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
50 * @param int $groupId group id
51 * @param int $forumId forum id
53 function ForumSearchQuery($words, $offset, $isExact, $groupId, $forumId) {
54 $this->groupId = $groupId;
55 $this->forumId = $forumId;
57 $this->SearchQuery($words, $offset, $isExact);
61 * getQuery - get the query built to get the search results
63 * @return array query+params array
68 $qpa = db_construct_qpa () ;
70 if (forge_get_config('use_fti')) {
71 $words = $this->getFormattedWords();
74 if(count($this->words)) {
75 $qpa = db_construct_qpa ($qpa,
76 'SELECT forum.msg_id, headline(forum.subject, q) AS subject, forum.post_date, users.realname FROM forum, users, to_tsquery($1) AS q, forum_idx as fi WHERE forum.group_forum_id = $2 AND forum.posted_by = users.user_id AND fi.msg_id = forum.msg_id AND vectors @@ q ',
79 $phraseOp = $this->getOperator();
81 $qpa = db_construct_qpa ($qpa,
82 'SELECT forum.msg_id, subject, forum.post_date, users.realname FROM forum, users WHERE forum.group_forum_id = $1 AND forum.posted_by = users.user_id ',
83 array ($this->forumId)) ;
86 if(count($this->phrases)) {
87 $qpa = db_construct_qpa ($qpa,
89 $qpa = $this->addMatchCondition($qpa, 'forum.body');
90 $qpa = db_construct_qpa ($qpa,
92 $qpa = $this->addMatchCondition($qpa, 'forum.subject');
93 $qpa = db_construct_qpa ($qpa,
96 if(count($this->words)) {
97 $qpa = db_construct_qpa ($qpa,
98 'ORDER BY rank(vectors, q) DESC') ;
100 $qpa = db_construct_qpa ($qpa,
101 'ORDER BY post_date DESC') ;
104 $qpa = db_construct_qpa ($qpa,
105 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname FROM forum,users WHERE users.user_id=forum.posted_by AND ((') ;
106 $qpa = $this->addIlikeCondition ($qpa, 'forum.body') ;
107 $qpa = db_construct_qpa ($qpa,
109 $qpa = $this->addIlikeCondition ($qpa, 'forum.subject') ;
110 $qpa = db_construct_qpa ($qpa,
111 ')) AND forum.group_forum_id=$1 GROUP BY msg_id, subject, post_date, realname',
112 array ($this->forumId)) ;
118 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
120 * @return array query+params array
122 function getSearchByIdQuery() {
123 $qpa = db_construct_qpa () ;
124 $qpa = db_construct_qpa ($qpa,
125 'SELECT msg_id FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
126 array ($this->searchId,
135 // c-file-style: "bsd"