3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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 NewsSearchQuery($words, $offset, $isExact, $groupId) {
45 $this->groupId = $groupId;
47 $this->SearchQuery($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 () ;
61 $group_id=$this->groupId;
63 if (count ($this->words)) {
64 $words = $this->getFormattedWords();
65 $qpa = db_construct_qpa ($qpa,
66 'SELECT headline(news_bytes.summary, q) as summary, news_bytes.post_date, news_bytes.forum_id, users.realname FROM news_bytes, users, to_tsquery($1) AS q, news_bytes_idx WHERE (news_bytes.group_id=$2 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 ',
70 $qpa = db_construct_qpa ($qpa,
71 'SELECT summary, news_bytes.post_date, news_bytes.forum_id, users.realname FROM news_bytes, users WHERE (news_bytes.group_id=$1 AND news_bytes.is_approved <> 4 AND news_bytes.submitted_by=users.user_id) AND (',
74 if (count ($this->phrases)) {
75 if (count ($this->words)) {
76 $qpa = db_construct_qpa ($qpa,
77 $this->getOperator()) ;
79 $qpa = db_construct_qpa ($qpa,
81 $qpa = $this->addMatchCondition ($qpa, 'summary') ;
82 $qpa = db_construct_qpa ($qpa,
84 $qpa = $this->addMatchCondition ($qpa, 'details') ;
85 $qpa = db_construct_qpa ($qpa,
88 if (count ($this->words)) {
89 $qpa = db_construct_qpa ($qpa,
90 ') ORDER BY rank(vectors, q) DESC, post_date DESC') ;
92 $qpa = db_construct_qpa ($qpa,
93 ') ORDER BY post_date DESC') ;
96 $qpa = db_construct_qpa ($qpa,
97 'SELECT news_bytes.summary, news_bytes.post_date, news_bytes.forum_id, users.realname FROM news_bytes, users WHERE (group_id=$1 AND is_approved <> 4 AND news_bytes.submitted_by = users.user_id AND ((',
98 array ($this->groupId)) ;
99 $qpa = $this->addIlikeCondition ($qpa, 'summary') ;
100 $qpa = db_construct_qpa ($qpa,
102 $qpa = $this->addIlikeCondition ($qpa, 'details') ;
103 $qpa = db_construct_qpa ($qpa,
104 ') ORDER BY post_date DESC') ;
112 // c-file-style: "bsd"