3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
7 * http://fusionforge.org
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 NewsSearchQuery extends SearchQuery {
39 * @param string $words words we are searching for
40 * @param int $offset offset
41 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
42 * @param int $groupId group id
44 function __construct($words, $offset, $isExact, $groupId) {
45 $this->groupId = $groupId;
47 parent::__construct($words, $offset, $isExact);
51 * getQuery - get the query built to get the search results
53 * @return array query+params array
58 $qpa = db_construct_qpa () ;
60 if (forge_get_config('use_fti')) {
61 $group_id=$this->groupId;
63 $words = $this->getFTIwords();
64 $qpa = db_construct_qpa ($qpa,
65 '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 ',
66 array ($this->field_separator,
69 if (count ($this->phrases)) {
70 $qpa = db_construct_qpa ($qpa,
72 $qpa = $this->addMatchCondition ($qpa, 'full_string_agg') ;
74 $qpa = db_construct_qpa ($qpa,
75 ' ORDER BY ts_rank(vectors, to_tsquery($1)) DESC, post_date DESC',
78 $qpa = db_construct_qpa ($qpa,
79 '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 ',
80 array ($this->field_separator,
82 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
83 $qpa = db_construct_qpa ($qpa,
84 ' ORDER BY post_date DESC') ;
92 // c-file-style: "bsd"