4 * Wiki Search Engine for Fusionforge
6 * Copyright 2004 (c) Dominik Haas, Gforge Team
7 * Copyright 2006 (c) Alain Peyrat
9 * This file is part of Fusionforge.
11 * Fusionforge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * Fusionforge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'search/SearchQuery.class.php';
28 class WikiSearchQuery extends SearchQuery {
40 * @param string $words words we are searching for
41 * @param int $offset offset
42 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
43 * @param int $groupId group id
45 function WikiSearchQuery($words, $offset, $isExact, $groupId) {
46 $this->groupId = $groupId;
48 $this->SearchQuery($words, $offset, $isExact);
52 * getQuery - get the query built to get the search results
54 * @return array query+params array
58 $pat = '_g'.$this->groupId.'_';
59 $len = strlen($pat)+1;
60 $words = join('&', $this->words);
63 'SELECT plugin_wiki_page.id AS id,
64 substring(plugin_wiki_page.pagename from '.$len.') AS pagename,
65 plugin_wiki_page.hits AS hits,
66 plugin_wiki_page.pagedata as pagedata,
67 plugin_wiki_version.version AS version,
68 plugin_wiki_version.mtime AS mtime,
69 plugin_wiki_version.minor_edit AS minor_edit,
70 plugin_wiki_version.content AS content,
71 plugin_wiki_version.versiondata AS versiondata
72 FROM plugin_wiki_nonempty, plugin_wiki_page, plugin_wiki_recent,
74 WHERE plugin_wiki_nonempty.id=plugin_wiki_page.id
75 AND plugin_wiki_page.id=plugin_wiki_recent.id
76 AND plugin_wiki_page.id=plugin_wiki_version.id
77 AND latestversion=version
78 AND substring(plugin_wiki_page.pagename from 0 for '.$len.') = $1
79 AND (idxFTI @@ to_tsquery($2))
80 ORDER BY ts_rank(idxFTI, to_tsquery($2)) DESC',
81 array ($pat, $words));