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. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'search/SearchQuery.class.php';
26 class ForumSearchQuery extends SearchQuery {
45 * @param string $words words we are searching for
46 * @param int $offset offset
47 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
48 * @param int $groupId group id
49 * @param int $forumId forum id
51 function ForumSearchQuery($words, $offset, $isExact, $groupId, $forumId) {
52 $this->groupId = $groupId;
53 $this->forumId = $forumId;
55 $this->SearchQuery($words, $offset, $isExact);
59 * getQuery - get the query built to get the search results
61 * @return array query+params array
66 $qpa = db_construct_qpa () ;
68 if (forge_get_config('use_fti')) {
69 $words = $this->getFTIwords();
70 $qpa = db_construct_qpa ($qpa,
71 'SELECT x.* FROM (SELECT forum.group_forum_id, forum.msg_id, ts_headline(forum.subject, $1::tsquery) AS subject, forum.post_date, users.realname, forum.subject||$2||forum.body as full_string_agg, forum_idx.vectors FROM forum, users, to_tsquery($1) AS q, forum_idx WHERE forum.group_forum_id = $3 AND forum.posted_by = users.user_id AND forum_idx.msg_id = forum.msg_id GROUP BY forum.group_forum_id, forum.msg_id, subject, body, post_date, realname, forum_idx.vectors) AS x WHERE vectors @@ $1::tsquery ',
73 $this->field_separator,
75 $phraseOp = $this->getOperator();
77 if(count($this->phrases)) {
78 $qpa = db_construct_qpa ($qpa,
80 $qpa = $this->addMatchCondition($qpa, 'full_string_agg');
81 $qpa = db_construct_qpa ($qpa,
84 $qpa = db_construct_qpa ($qpa,
85 'ORDER BY ts_rank(vectors, $1) DESC',
88 $qpa = db_construct_qpa ($qpa,
89 'SELECT x.* FROM (SELECT forum.group_forum_id, forum.msg_id, forum.subject, forum.post_date, users.realname, forum.subject||$1||forum.body as full_string_agg FROM forum,users WHERE users.user_id=forum.posted_by AND forum.group_forum_id=$2 GROUP BY forum.group_forum_id, msg_id, subject, post_date, realname, body) AS x WHERE ',
90 array ($this->field_separator,
92 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
93 $qpa = db_construct_qpa ($qpa,
100 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
102 * @return array query+params array
104 function getSearchByIdQuery() {
105 $qpa = db_construct_qpa () ;
106 $qpa = db_construct_qpa ($qpa,
107 'SELECT msg_id FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
108 array ($this->searchId,
117 // c-file-style: "bsd"