File: WikiSearchQuery.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (83 lines) | stat: -rw-r--r-- 2,631 bytes parent folder | download | duplicates (4)
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
<?php
/**
 * WikiPlugin Class
 * Wiki Search Engine for Fusionforge
 *
 * Copyright 2004 (c) Dominik Haas, Gforge Team
 * Copyright 2006 (c) Alain Peyrat
 *
 * This file is part of Fusionforge.
 *
 * Fusionforge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Fusionforge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

require_once $gfcommon.'search/SearchQuery.class.php';

class WikiSearchQuery extends SearchQuery {

	/**
	* group id
	*
	* @var int $groupId
	*/
	var $groupId;

	/**
	 * 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
	 */
	function WikiSearchQuery($words, $offset, $isExact, $groupId) {
		$this->groupId = $groupId;

		$this->SearchQuery($words, $offset, $isExact);
	}

	/**
	 * getQuery - get the query built to get the search results
	 *
	 * @return array query+params array
	 */
	function getQuery() {

		$pat = '_g'.$this->groupId.'_';
		$len = strlen($pat)+1;
		$words = join('&', $this->words);

		return array (
			 'SELECT plugin_wiki_page.id AS id,
					substring(plugin_wiki_page.pagename from '.$len.') AS pagename,
					plugin_wiki_page.hits AS hits,
					plugin_wiki_page.pagedata as pagedata,
					plugin_wiki_version.version AS version,
					plugin_wiki_version.mtime AS mtime,
					plugin_wiki_version.minor_edit AS minor_edit,
					plugin_wiki_version.content AS content,
					plugin_wiki_version.versiondata AS versiondata
				FROM plugin_wiki_nonempty, plugin_wiki_page, plugin_wiki_recent,
					plugin_wiki_version
				WHERE plugin_wiki_nonempty.id=plugin_wiki_page.id
					AND plugin_wiki_page.id=plugin_wiki_recent.id
					AND plugin_wiki_page.id=plugin_wiki_version.id
					AND latestversion=version
					AND substring(plugin_wiki_page.pagename from 0 for '.$len.') = $1
					AND (idxFTI @@ to_tsquery($2))
				ORDER BY ts_rank(idxFTI, to_tsquery($2)) DESC',
			 array ($pat, $words));
	}
}