3 * FusionForge search engine
5 * Copyright 1999-2001, VA Linux Systems, Inc
6 * Copyright 2004, Guillaume Smet/Open Wide
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'search/SearchQuery.class.php';
27 class ForumSearchQuery extends SearchQuery {
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 int $forumId forum id
52 function __construct($words, $offset, $isExact, $groupId, $forumId) {
53 $this->groupId = $groupId;
54 $this->forumId = $forumId;
56 parent::__construct($words, $offset, $isExact);
60 * getQuery - get the query built to get the search results
62 * @return array query+params array
67 $qpa = db_construct_qpa () ;
69 if (forge_get_config('use_fti')) {
70 $words = $this->getFTIwords();
71 $qpa = db_construct_qpa ($qpa,
72 '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 ',
74 $this->field_separator,
76 $phraseOp = $this->getOperator();
78 if(count($this->phrases)) {
79 $qpa = db_construct_qpa ($qpa,
81 $qpa = $this->addMatchCondition($qpa, 'full_string_agg');
82 $qpa = db_construct_qpa ($qpa,
85 $qpa = db_construct_qpa ($qpa,
86 'ORDER BY ts_rank(vectors, $1) DESC',
89 $qpa = db_construct_qpa ($qpa,
90 '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 ',
91 array ($this->field_separator,
93 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
94 $qpa = db_construct_qpa ($qpa,
103 // c-file-style: "bsd"