File: ForumSearchQuery.class

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (89 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: ForumSearchQuery.class 5273 2006-02-08 18:47:59Z danper $
 */

require_once('common/search/SearchQuery.class');

class ForumSearchQuery extends SearchQuery {
	
	/**
	 * group id
	 *
	 * @var int $groupId
	 */
	var $groupId;
	
	/**
	 * forum id
	 *
	 * @var int $groupId
	 */
	var $forumId;
	
	/**
	 * Constructor
	 *
	 * @param string $words words we are searching for
	 * @param int $offset offset
	 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
	 * @param int $groupId group id
	 * @param int $forumId forum id
	 */
	function ForumSearchQuery($words, $offset, $isExact, $groupId, $forumId) {
		$this->groupId = $groupId;
		$this->forumId = $forumId;
		
		$this->SearchQuery($words, $offset, $isExact);
	}

	/**
	 * getQuery - get the sql query built to get the search results
	 *
	 * @return string sql query to execute
	 */
	function getQuery() {
		global $sys_use_fti;
		if ($sys_use_fti) {
			$words = $this->getFormattedWords();
			$sql = "SELECT forum.msg_id, headline(forum.subject, q) AS subject, forum.post_date, users.realname "
					." FROM forum, users, to_tsquery('$words') AS q, forum_idx as fi "
					." WHERE fi.msg_id = forum.msg_id AND vectors @@ q "
					." AND users.user_id=forum.posted_by AND forum.group_forum_id=$this->forumId "
					." ORDER BY rank(vectors, q) DESC";
		} else {
			$sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname '
				. 'FROM forum,users '
				. 'WHERE users.user_id=forum.posted_by '
				. 'AND (('.$this->getIlikeCondition('forum.body', $this->words).') '
				. 'OR ('.$this->getIlikeCondition('forum.subject', $this->words).')) '
				. 'AND forum.group_forum_id=\''.$this->forumId.'\' '
				. 'GROUP BY msg_id, subject, post_date, realname';
		}
		return $sql;
	}
	
	/**
	 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
	 *
	 * @return string sql query to execute
	 */	
	function getSearchByIdQuery() {
		$sql = 'SELECT msg_id '
			. 'FROM forum '
			. 'WHERE msg_id=\''.$this->searchId.'\' '
			. 'AND group_forum_id=\''.$this->forumId.'\'';

		return $sql;
	}
}

?>