6 * Portions Copyright 1999-2001 (c) VA Linux Systems
7 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
14 require_once $gfcommon.'search/SearchQuery.class.php';
16 class ForumSearchQuery extends SearchQuery {
35 * @param string $words words we are searching for
36 * @param int $offset offset
37 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
38 * @param int $groupId group id
39 * @param int $forumId forum id
41 function ForumSearchQuery($words, $offset, $isExact, $groupId, $forumId) {
42 $this->groupId = $groupId;
43 $this->forumId = $forumId;
45 $this->SearchQuery($words, $offset, $isExact);
49 * getQuery - get the sql query built to get the search results
51 * @return string sql query to execute
56 $words = $this->getFormattedWords();
57 if(count($this->words)) {
58 $tsquery0 = "headline(forum.subject, q) AS subject";
59 $tsquery = ", to_tsquery('".$words."') AS q, forum_idx as fi";
60 $tsmatch = "vectors @@ q";
62 $tsjoin = 'AND fi.msg_id = forum.msg_id';
63 $orderBy = "ORDER BY rank(vectors, q) DESC";
64 $phraseOp = $this->getOperator();
66 $tsquery0 = "subject";
71 $orderBy = "ORDER BY post_date DESC";
75 if(count($this->phrases)) {
76 $bodyCond = $this->getMatchCond('forum.body', $this->phrases);
77 $subjectCond = $this->getMatchCond('forum.subject', $this->phrases);
78 $phraseCond = $phraseOp.' (('.$bodyCond.') OR ('.$subjectCond.'))';
80 $sql = "SELECT forum.msg_id, $tsquery0, forum.post_date, users.realname
81 FROM forum, users $tsquery
83 forum.group_forum_id =".$this->forumId."
84 AND forum.posted_by = users.user_id
85 $tsjoin AND ($tsmatch $phraseCond)
88 $sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname '
90 . 'WHERE users.user_id=forum.posted_by '
91 . 'AND (('.$this->getIlikeCondition('forum.body', $this->words).') '
92 . 'OR ('.$this->getIlikeCondition('forum.subject', $this->words).')) '
93 . 'AND forum.group_forum_id=\''.$this->forumId.'\' '
94 . 'GROUP BY msg_id, subject, post_date, realname';
100 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
102 * @return string sql query to execute
104 function getSearchByIdQuery() {
105 $sql = 'SELECT msg_id '
107 . 'WHERE msg_id=\''.$this->searchId.'\' '
108 . 'AND group_forum_id=\''.$this->forumId.'\'';