3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'search/SearchQuery.class.php';
27 class FrsSearchQuery extends SearchQuery {
37 * flag if non public items are returned
39 * @var boolean $showNonPublic
46 * @param string $words words we are searching for
47 * @param int $offset offset
48 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
49 * @param int $groupId group id
50 * @param array $sections sections to search in
52 function FrsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
53 $this->groupId = $groupId;
54 $this->showNonPublic = $showNonPublic;
56 $this->SearchQuery($words, $offset, $isExact);
58 $this->setSections($sections);
62 * getQuery - get the query built to get the search results
64 * @return array query+params array
69 $qpa = db_construct_qpa () ;
71 if (forge_get_config('use_fti')) {
72 $qpa = db_construct_qpa () ;
73 $qpa = db_construct_qpa ($qpa,
74 'SELECT ts_headline(frs_package.name, q) AS package_name, ts_headline(frs_release.name, q) as release_name, frs_release.release_date, frs_release.release_id, users.realname FROM frs_file, frs_release, users, frs_package, to_tsquery($1) AS q, frs_release_idx r, frs_file_idx f WHERE frs_release.released_by = users.user_id AND r.release_id = frs_release.release_id AND f.file_id = frs_file.file_id AND frs_package.package_id = frs_release.package_id AND frs_file.release_id=frs_release.release_id AND frs_package.group_id=$2 ',
75 array ($this->getFTIwords(),
77 if ($this->sections != SEARCH__ALL_SECTIONS) {
78 $qpa = db_construct_qpa ($qpa,
79 'AND frs_package.package_id = ANY ($1) ',
80 array (db_int_array_to_any_clause ($this->sections))) ;
82 if (!$this->showNonPublic) {
83 $qpa = db_construct_qpa ($qpa,
84 'AND is_public = 1 ') ;
86 $qpa = db_construct_qpa ($qpa,
87 'AND (f.vectors @@ q OR r.vectors @@ q) ') ;
88 if(count($this->phrases)) {
89 $qpa = db_construct_qpa ($qpa,
91 $qpa = $this->addMatchCondition($qpa, 'frs_release.changes');
92 $qpa = db_construct_qpa ($qpa,
94 $qpa = $this->addMatchCondition($qpa, 'frs_release.notes');
95 $qpa = db_construct_qpa ($qpa,
97 $qpa = $this->addMatchCondition($qpa, 'frs_release.name');
98 $qpa = db_construct_qpa ($qpa,
100 $qpa = $this->addMatchCondition($qpa, 'frs_file.filename');
101 $qpa = db_construct_qpa ($qpa,
105 $qpa = db_construct_qpa ($qpa,
106 ' ORDER BY frs_package.name, frs_release.name') ;
109 $qpa = db_construct_qpa ($qpa,
110 'SELECT frs_package.name as package_name, frs_release.name as release_name, frs_release.release_date, frs_release.release_id, users.realname FROM frs_file, frs_release, users, frs_package WHERE frs_release.released_by = users.user_id AND frs_package.package_id = frs_release.package_id AND frs_file.release_id=frs_release.release_id AND frs_package.group_id = $1 ',
111 array ($this->groupId)) ;
112 if ($this->sections != SEARCH__ALL_SECTIONS) {
113 $qpa = db_construct_qpa ($qpa,
114 'AND frs_package.package_id = ANY ($1) ',
115 array (db_int_array_to_any_clause ($this->sections))) ;
117 if (!$this->showNonPublic) {
118 $qpa = db_construct_qpa ($qpa,
119 'AND is_public = 1 ') ;
121 $qpa = db_construct_qpa ($qpa,
123 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.changes') ;
124 $qpa = db_construct_qpa ($qpa,
126 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.notes') ;
127 $qpa = db_construct_qpa ($qpa,
129 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.name') ;
130 $qpa = db_construct_qpa ($qpa,
132 $qpa = $this->addIlikeCondition ($qpa, 'frs_file.filename') ;
133 $qpa = db_construct_qpa ($qpa,
134 ')) ORDER BY frs_package.name, frs_release.name') ;
140 * getSections - returns the list of available forums
142 * @param $groupId int group id
143 * @param $showNonPublic boolean if we should consider non public sections
145 static function getSections($groupId, $showNonPublic) {
146 $sql = 'SELECT package_id, name FROM frs_package WHERE group_id=$1';
147 if(!$showNonPublic) {
148 $sql .= ' AND is_public=1';
150 $sql .= ' ORDER BY name';
153 $res = db_query_params ($sql,
155 while($data = db_fetch_array($res)) {
156 $sections[$data['package_id']] = $data['name'];
164 // c-file-style: "bsd"