3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
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 FusionForge; 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 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 __construct($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
54 $this->groupId = $groupId;
55 $this->showNonPublic = $showNonPublic;
57 parent::__construct($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 $qpa = db_construct_qpa () ;
74 $qpa = db_construct_qpa ($qpa,
75 '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 ',
76 array ($this->getFTIwords(),
78 if ($this->sections != SEARCH__ALL_SECTIONS) {
79 $qpa = db_construct_qpa ($qpa,
80 'AND frs_package.package_id = ANY ($1) ',
81 array (db_int_array_to_any_clause ($this->sections))) ;
83 if (!$this->showNonPublic) {
84 $qpa = db_construct_qpa ($qpa,
85 'AND is_public = 1 ') ;
87 $qpa = db_construct_qpa ($qpa,
88 'AND (f.vectors @@ q OR r.vectors @@ q) ') ;
89 if(count($this->phrases)) {
90 $qpa = db_construct_qpa ($qpa,
92 $qpa = $this->addMatchCondition($qpa, 'frs_release.changes');
93 $qpa = db_construct_qpa ($qpa,
95 $qpa = $this->addMatchCondition($qpa, 'frs_release.notes');
96 $qpa = db_construct_qpa ($qpa,
98 $qpa = $this->addMatchCondition($qpa, 'frs_release.name');
99 $qpa = db_construct_qpa ($qpa,
101 $qpa = $this->addMatchCondition($qpa, 'frs_file.filename');
102 $qpa = db_construct_qpa ($qpa,
106 $qpa = db_construct_qpa ($qpa,
107 ' ORDER BY frs_package.name, frs_release.name') ;
110 $qpa = db_construct_qpa ($qpa,
111 '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 ',
112 array ($this->groupId)) ;
113 if ($this->sections != SEARCH__ALL_SECTIONS) {
114 $qpa = db_construct_qpa ($qpa,
115 'AND frs_package.package_id = ANY ($1) ',
116 array (db_int_array_to_any_clause ($this->sections))) ;
118 if (!$this->showNonPublic) {
119 $qpa = db_construct_qpa ($qpa,
120 'AND is_public = 1 ') ;
122 $qpa = db_construct_qpa ($qpa,
124 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.changes') ;
125 $qpa = db_construct_qpa ($qpa,
127 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.notes') ;
128 $qpa = db_construct_qpa ($qpa,
130 $qpa = $this->addIlikeCondition ($qpa, 'frs_release.name') ;
131 $qpa = db_construct_qpa ($qpa,
133 $qpa = $this->addIlikeCondition ($qpa, 'frs_file.filename') ;
134 $qpa = db_construct_qpa ($qpa,
135 ')) ORDER BY frs_package.name, frs_release.name') ;
141 * getSections - returns the list of available forums
143 * @param $groupId int group id
144 * @param $showNonPublic boolean if we should consider non public sections
146 static function getSections($groupId, $showNonPublic) {
147 $sql = 'SELECT package_id, name FROM frs_package WHERE group_id=$1';
148 if(!$showNonPublic) {
149 $sql .= ' AND is_public=1';
151 $sql .= ' ORDER BY name';
154 $res = db_query_params ($sql,
156 while($data = db_fetch_array($res)) {
157 $sections[$data['package_id']] = $data['name'];
165 // c-file-style: "bsd"