3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2011, Franck Villaume - Capgemini
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
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
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along 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 DocsAllSearchQuery extends SearchQuery {
31 * array flags if non public items are returned
33 * @var $parametersValues
35 var $parametersValues;
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 array $sections sections to search in
44 * @param boolean $showNonPublic flag if private sections are searched too
46 function __construct($words, $offset, $isExact = true, $sections=SEARCH__ALL_SECTIONS, $parametersValues, $showNonPublic = false) {
47 $this->parametersValues = $parametersValues;
48 $this->showNonPublic = $showNonPublic;
49 parent::__construct($words, $offset, $isExact);
53 * getQuery - get the sql query built to get the search results
55 * @return string sql query to execute
58 $qpa = db_construct_qpa();
59 $qpa = db_construct_qpa($qpa,
60 'SELECT doc_data.group_id, groups.group_name as project_name,doc_groups.groupname,
61 doc_data.docid, doc_data.title, doc_data.description, doc_data.filetype,
62 doc_data.filename, doc_groups.groupname
63 FROM doc_data, doc_groups, groups
64 WHERE doc_data.doc_group = doc_groups.doc_group
65 AND doc_data.group_id = groups.group_id',
67 if ($this->sections != SEARCH__ALL_SECTIONS) {
68 $qpa = db_construct_qpa($qpa,'AND doc_groups.doc_group = ANY ($1) ',
69 db_int_array_to_any_clause($this->sections));
71 if ($this->showNonPublic) {
72 $qpa = db_construct_qpa($qpa, ' AND doc_data.stateid IN (1, 4, 5)');
74 $qpa = db_construct_qpa($qpa, ' AND doc_data.stateid = 1');
77 $qpa = db_construct_qpa($qpa, ' AND ((');
78 $qpa = $this->addIlikeCondition($qpa, 'title', $this->words);
79 $qpa = db_construct_qpa($qpa, ') OR (');
80 $qpa = $this->addIlikeCondition($qpa, 'description', $this->words);
81 $qpa = db_construct_qpa($qpa, ') OR (');
82 $qpa = $this->addIlikeCondition($qpa, 'data_words', $this->words);
83 $qpa = db_construct_qpa ($qpa, ')) ORDER BY doc_groups.groupname, doc_data.docid') ;
92 // c-file-style: "bsd"