3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * http://fusionforge.org
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 NewsSearchQuery extends SearchQuery {
38 * @param string $words words we are searching for
39 * @param int $offset offset
40 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
41 * @param int $groupId group id
43 function NewsSearchQuery($words, $offset, $isExact, $groupId) {
44 $this->groupId = $groupId;
46 $this->SearchQuery($words, $offset, $isExact);
50 * getQuery - get the query built to get the search results
52 * @return array query+params array
57 $qpa = db_construct_qpa () ;
59 if (forge_get_config('use_fti')) {
60 $group_id=$this->groupId;
62 $words = $this->getFTIwords();
63 $qpa = db_construct_qpa ($qpa,
64 '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 ',
65 array ($this->field_separator,
68 if (count ($this->phrases)) {
69 $qpa = db_construct_qpa ($qpa,
71 $qpa = $this->addMatchCondition ($qpa, 'full_string_agg') ;
73 $qpa = db_construct_qpa ($qpa,
74 ' ORDER BY ts_rank(vectors, to_tsquery($1)) DESC, post_date DESC',
77 $qpa = db_construct_qpa ($qpa,
78 '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 ',
79 array ($this->field_separator,
81 $qpa = $this->addIlikeCondition ($qpa, 'full_string_agg') ;
82 $qpa = db_construct_qpa ($qpa,
83 ' ORDER BY post_date DESC') ;
91 // c-file-style: "bsd"