3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'search/SearchQuery.class.php';
28 class FrsSearchQuery extends SearchQuery {
38 * flag if non public items are returned
40 * @var boolean $showNonPublic
47 * @param string $words words we are searching for
48 * @param int $offset offset
49 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
50 * @param int $groupId group id
51 * @param array $sections sections to search in
53 function FrsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
54 $this->groupId = $groupId;
55 $this->showNonPublic = $showNonPublic;
57 $this->SearchQuery($words, $offset, $isExact);
59 $this->setSections($sections);
63 * getQuery - get the query built to get the search results
65 * @return array query+params array
70 $qpa = db_construct_qpa () ;
72 if (forge_get_config('use_fti')) {
73 if(count($this->words)) {
74 $qpa = db_construct_qpa () ;
75 $qpa = db_construct_qpa ($qpa,
76 'SELECT headline(frs_package.name, q) AS package_name, 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 ',
77 array ($this->getFormattedWords(),
80 $qpa = db_construct_qpa ($qpa,
81 '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 ',
82 array ($this->groupId)) ;
84 if ($this->sections != SEARCH__ALL_SECTIONS) {
85 $qpa = db_construct_qpa ($qpa,
86 'AND frs_package.package_id = ANY ($1) ',
87 array (db_int_array_to_any_clause ($this->sections))) ;
89 if (!$this->showNonPublic) {
90 $qpa = db_construct_qpa ($qpa,
91 'AND is_public = 1 ') ;
93 if (count ($this->words)) {
94 $qpa = db_construct_qpa ($qpa,
95 'AND (f.vectors @@ q OR r.vectors @@ q) ') ;
97 if(count($this->phrases)) {
98 $qpa = db_construct_qpa ($qpa,
100 $qpa = $this->addMatchCondition($qpa, 'frs_release.changes');
101 $qpa = db_construct_qpa ($qpa,
103 $qpa = $this->addMatchCondition($qpa, 'frs_release.notes');
104 $qpa = db_construct_qpa ($qpa,
106 $qpa = $this->addMatchCondition($qpa, 'frs_release.name');
107 $qpa = db_construct_qpa ($qpa,
109 $qpa = $this->addMatchCondition($qpa, 'frs_file.filename');
110 $qpa = db_construct_qpa ($qpa,
114 $qpa = db_construct_qpa ($qpa,
115 ' ORDER BY frs_package.name, frs_release.name') ;
118 $qpa = db_construct_qpa ($qpa,
119 '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 ',
120 array ($this->groupId)) ;
121 if ($this->sections != SEARCH__ALL_SECTIONS) {
122 $qpa = db_construct_qpa ($qpa,
123 'AND frs_package.package_id = ANY ($1) ',
124 array (db_int_array_to_any_clause ($this->sections))) ;
126 if (!$this->showNonPublic) {
127 $qpa = db_construct_qpa ($qpa,
128 'AND is_public = 1 ') ;
130 $qpa = db_construct_qpa ($qpa,
132 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.changes') ;
133 $qpa = db_construct_qpa ($qpa,
135 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.notes') ;
136 $qpa = db_construct_qpa ($qpa,
138 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.name') ;
139 $qpa = db_construct_qpa ($qpa,
141 $qpa = $this->addIlikeCondition ($qpa, 'frs_file.filename') ;
142 $qpa = db_construct_qpa ($qpa,
143 ')) ORDER BY frs_package.name, frs_release.name') ;
149 * getSections - returns the list of available forums
151 * @param $groupId int group id
152 * @param $showNonPublic boolean if we should consider non public sections
154 function getSections($groupId, $showNonPublic) {
155 $sql = 'SELECT package_id, name FROM frs_package WHERE group_id=$1';
156 if(!$showNonPublic) {
157 $sql .= ' AND is_public=1';
159 $sql .= ' ORDER BY name';
162 $res = db_query_params ($sql,
164 while($data = db_fetch_array($res)) {
165 $sections[$data['package_id']] = $data['name'];
173 // c-file-style: "bsd"