3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
7 * Copyright 2013, French Ministry of National Education
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'search/SearchQuery.class.php';
28 class NewsSearchQuery extends SearchQuery {
40 * @param string $words words we are searching for
41 * @param int $offset offset
42 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
43 * @param int $groupId group id
45 function __construct($words, $offset, $isExact, $groupId) {
46 $this->groupId = $groupId;
48 parent::__construct($words, $offset, $isExact);
52 * getQuery - get the query built to get the search results
54 * @return array query+params array
59 $qpa = db_construct_qpa () ;
61 if (forge_get_config('use_fti')) {
62 $group_id=$this->groupId;
64 $words = $this->getFTIwords();
65 $qpa = db_construct_qpa ($qpa,
66 'SELECT x.* FROM (SELECT ts_headline(news_bytes.summary, q) as summary, news_bytes.post_date, news_bytes.forum_id, users.realname, summary||$1||details AS full_string_agg, news_bytes_idx.vectors FROM news_bytes, users, to_tsquery($2) AS q, news_bytes_idx WHERE (news_bytes.group_id=$3 AND news_bytes.is_approved <> 4 AND news_bytes_idx.id = news_bytes.id AND news_bytes.submitted_by=users.user_id) AND vectors @@ q) AS x ',
67 array ($this->field_separator,
70 if (count ($this->phrases)) {
71 $qpa = db_construct_qpa ($qpa,
73 $qpa = $this->addMatchCondition ($qpa, 'full_string_agg') ;
75 $qpa = db_construct_qpa ($qpa,
76 ' ORDER BY ts_rank(vectors, to_tsquery($1)) DESC, post_date DESC',
79 $qpa = db_construct_qpa ($qpa,
80 'SELECT x.* FROM (SELECT news_bytes.summary, news_bytes.post_date, news_bytes.forum_id, users.realname, summary||$1||details AS full_string_agg FROM news_bytes, users WHERE group_id=$2 AND is_approved <> 4 AND news_bytes.submitted_by = users.user_id) AS x WHERE ',
81 array ($this->field_separator,
83 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
84 $qpa = db_construct_qpa ($qpa,
85 ' ORDER BY post_date DESC') ;
91 * getSections - returns the list of available forums
93 * @param $groupId int group id
94 * @param $showNonPublic boolean if we should consider non public sections
96 static function getSections($groupId, $showNonPublic=false) {
98 // Select survey of the project
99 $sql = 'SELECT group_forum_id, forum_name FROM forum_group_list WHERE group_id = $1 AND ';
100 $sql .= 'group_forum_id IN (SELECT forum_id FROM news_bytes) ORDER BY forum_name';
103 $res = db_query_params ($sql,
105 while($data = db_fetch_array($res)) {
106 if (forge_check_perm('forum',$data['group_forum_id'],'read')) {
107 $sections[$data['group_forum_id']] = $data['forum_name'];
116 // c-file-style: "bsd"