[Fusionforge-commits] FusionForge branch master updated. v6.0.3-274-gd0416f2

Franck Villaume nerville at libremir.placard.fr.eu.org
Sat Dec 12 14:43:07 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  d0416f20595f246ae41eb8012bfcdd5437941401 (commit)
      from  e5ce0594fc79107c25a945307a2066b1e58cf303 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=d0416f20595f246ae41eb8012bfcdd5437941401

commit d0416f20595f246ae41eb8012bfcdd5437941401
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Sat Dec 12 14:42:27 2015 +0100

    docman search engine: unify DocsAll & Docs search

diff --git a/src/common/search/DocsAllSearchQuery.class.php b/src/common/search/DocsAllSearchQuery.class.php
deleted file mode 100644
index 39504b7..0000000
--- a/src/common/search/DocsAllSearchQuery.class.php
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-/**
- * FusionForge search engine
- *
- * Copyright 2004, Dominik Haas
- * Copyright 2011, Franck Villaume - Capgemini
- * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
- * Copyright 2013, French Minitry of National Education
- *
- * This file is part of FusionForge.
- *
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-require_once $gfcommon.'search/SearchQuery.class.php';
-
-class DocsAllSearchQuery extends SearchQuery {
-
-   /**
-	* array flags if non public items are returned
-	*
-	* @var $parametersValues
-	*/
-	var $parametersValues;
-
-	/**
-	 * Constructor
-	 *
-	 * @param    string $words words we are searching for
-	 * @param    int $offset offset
-	 * @param    bool $isExact if we want to search for all the words or if only one matching the query is sufficient
-	 * @param int|string $sections sections to search in
-	 * @param    array $parametersValues
-	 * @param    bool $showNonPublic flag if private sections are searched too
-	 */
-	function __construct($words, $offset, $isExact = true, $sections=SEARCH__ALL_SECTIONS, $parametersValues, $showNonPublic = false) {
-		$this->parametersValues = $parametersValues;
-		$this->showNonPublic = $showNonPublic;
-		parent::__construct($words, $offset, $isExact);
-	}
-
-	/**
-	 * getQuery - get the sql query built to get the search results
-	 *
-	 * @return string sql query to execute
-	 */
-	function getQuery() {
-		$qpa = db_construct_qpa();
-		$qpa = db_construct_qpa($qpa,
-					'SELECT doc_data.group_id, groups.group_name as project_name,doc_groups.groupname,
-					doc_data.docid, doc_data.title, doc_data.description, doc_data.filetype,
-					doc_data.filename, doc_groups.groupname
-					FROM doc_data, doc_groups, groups
-					WHERE doc_data.doc_group = doc_groups.doc_group
-					AND doc_data.group_id = groups.group_id',
-					array());
-		if ($this->sections != SEARCH__ALL_SECTIONS) {
-			$qpa = db_construct_qpa($qpa,'AND doc_groups.doc_group = ANY ($1) ',
-						db_int_array_to_any_clause($this->sections));
-		}
-		if ($this->showNonPublic) {
-			$qpa = db_construct_qpa($qpa, ' AND doc_data.stateid IN (1, 4, 5)');
-		} else {
-			$qpa = db_construct_qpa($qpa, ' AND doc_data.stateid = 1');
-		}
-
-		$qpa = db_construct_qpa($qpa, ' AND ((');
-		$qpa = $this->addIlikeCondition($qpa, 'title', $this->words);
-		$qpa = db_construct_qpa($qpa, ') OR (');
-		$qpa = $this->addIlikeCondition($qpa, 'description', $this->words);
-		$qpa = db_construct_qpa($qpa, ') OR (');
-		$qpa = $this->addIlikeCondition($qpa, 'data_words', $this->words);
-		$qpa = db_construct_qpa($qpa, ')) ORDER BY groups.group_name, doc_groups.groupname, doc_data.title') ;
-
-		return $qpa;
-	}
-
-}
-
-// Local Variables:
-// mode: php
-// c-file-style: "bsd"
-// End:
diff --git a/src/common/search/DocsSearchQuery.class.php b/src/common/search/DocsSearchQuery.class.php
index 1941fb8..783f281 100644
--- a/src/common/search/DocsSearchQuery.class.php
+++ b/src/common/search/DocsSearchQuery.class.php
@@ -5,8 +5,8 @@
  * Copyright 2004, Dominik Haas
  * Copyright 2009, Roland Mas
  * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
- * Copyright 2013,2015 Franck Villaume - TrivialDev
  * Copyright 2013, French Ministry of National Education
+ * Copyright 2013,2015 Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -32,9 +32,9 @@ class DocsSearchQuery extends SearchQuery {
 	/**
 	* group id
 	*
-	* @var int $groupId
+	* @var array $groupIdArr
 	*/
-	var $groupId;
+	var $groupIdArr;
 
 	/**
 	* flag if non public items are returned
@@ -49,18 +49,50 @@ class DocsSearchQuery extends SearchQuery {
 	 * @param	string	$words words we are searching for
 	 * @param	int	$offset offset
 	 * @param	bool	$isExact if we want to search for all the words or if only one matching the query is sufficient
-	 * @param	int	$groupId group id
+	 * @param	array	$groupIdArr array containing group ids
 	 * @param	string	$sections sections to search in
 	 * @param	bool	$showNonPublic flag if private sections are searched too
 	 */
-	function __construct($words, $offset, $isExact, $groupId, $sections = SEARCH__ALL_SECTIONS, $showNonPublic = false, $rowsPerPage = SEARCH__DEFAULT_ROWS_PER_PAGE, $options = array()) {
-		$this->groupId = $groupId;
+	function __construct($words, $offset, $isExact, $groupIdArr, $sections = SEARCH__ALL_SECTIONS, $showNonPublic = false, $rowsPerPage = SEARCH__DEFAULT_ROWS_PER_PAGE, $options = array()) {
+
+		$this->groupIdArr = $groupIdArr;
 		$this->showNonPublic = $showNonPublic;
 		parent::__construct($words, $offset, $isExact, $rowsPerPage, $options);
 		$this->setSections($sections);
 	}
 
 	/**
+	 * addCommonQPA - add common sql commands to existing QPA
+	 *
+	 * @return	array	query+params array
+	 */
+	function addCommonQPA($qpa) {
+		$options = $this->options;
+		if (count($this->groupIdArr)) {
+			$qpa = db_construct_qpa($qpa, ' AND doc_data.group_id = ANY ($1) ', array(db_int_array_to_any_clause($this->groupIdArr)));
+		}
+		if ($this->sections != SEARCH__ALL_SECTIONS) {
+			$qpa = db_construct_qpa($qpa, ' AND doc_groups.doc_group = ANY ($1)', array(db_int_array_to_any_clause($this->sections)));
+		}
+		if ($this->showNonPublic) {
+			$qpa = db_construct_qpa($qpa,
+						 ' AND doc_data.stateid IN (1, 4, 5)') ;
+		} else {
+			$qpa = db_construct_qpa($qpa,
+						 ' AND doc_data.stateid = 1') ;
+		}
+
+		if (isset($options['date_begin']) && !isset($options['date_end'])) {
+			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate >= $1', array($options['date_begin']));
+		} elseif (!isset($options['date_begin']) && isset($options['date_end'])) {
+			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate <= $1', array($options['date_end']));
+		} elseif (isset($options['date_begin']) && isset($options['date_end'])) {
+			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate between $1 and $2', array($options['date_begin'], $$options['date_end']));
+		}
+		return $qpa;
+	}
+
+	/**
 	 * getQuery - get the query built to get the search results
 	 *
 	 * @return	array	query+params array
@@ -71,33 +103,14 @@ class DocsSearchQuery extends SearchQuery {
 		} else {
 			$options = $this->options;
 			$qpa = db_construct_qpa(false,
-						 'SELECT x.* FROM (SELECT doc_data.docid, doc_data.title, doc_data.filename, doc_data.description, doc_groups.groupname, title||$1||description AS full_string_agg FROM doc_data, doc_groups WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.group_id = $2',
-						 array ($this->field_separator,
-							$this->groupId)) ;
-			if ($this->sections != SEARCH__ALL_SECTIONS) {
-				$qpa = db_construct_qpa($qpa,
-							 'AND doc_groups.doc_group = ANY ($1) ',
-							 array( db_int_array_to_any_clause ($this->sections))) ;
-			}
-			if ($this->showNonPublic) {
-				$qpa = db_construct_qpa($qpa, ' AND doc_data.stateid IN (1, 4, 5)');
-			} else {
-				$qpa = db_construct_qpa($qpa, ' AND doc_data.stateid = 1');
-			}
-
-			if (isset($options['date_begin']) && !isset($options['date_end'])) {
-				$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate >= $1', array($options['date_begin']));
-			} elseif (!isset($options['date_begin']) && isset($options['date_end'])) {
-				$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate <= $1', array($options['date_end']));
-			} elseif (isset($options['date_begin']) && isset($options['date_end'])) {
-				$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate between $1 and $2', array($options['date_begin'], $$options['date_end']));
-			}
+						 'SELECT x.* FROM (SELECT doc_data.docid, doc_data.title, doc_data.filename, doc_data.description, doc_groups.groupname, title||$1||description AS full_string_agg, groups.group_name as project_name FROM doc_data, doc_groups, groups WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.group_id = groups.group_id ',
+						 array ($this->field_separator));
 
-			$qpa = db_construct_qpa($qpa,
-						 ') AS x WHERE ') ;
+			$qpa = $this->addCommonQPA($qpa);
+
+			$qpa = db_construct_qpa($qpa, ') AS x WHERE ') ;
 			$qpa = $this->addIlikeCondition($qpa, 'full_string_agg');
-			$qpa = db_construct_qpa($qpa,
-						 ' ORDER BY x.groupname, x.title') ;
+			$qpa = db_construct_qpa($qpa, ' ORDER BY x.groupname, x.title');
 		}
 		return $qpa;
 	}
@@ -105,42 +118,18 @@ class DocsSearchQuery extends SearchQuery {
 	function getFTIQuery() {
 		$words = $this->getFTIwords();
 		$options = $this->options;
-		$group_id = $this->groupId;
 		if (!isset($options['insideDocuments']) || !$options['insideDocuments']) {
 			$qpa = db_construct_qpa(false,
-					'SELECT x.* FROM (SELECT doc_data.docid, doc_data.filename, ts_headline(doc_data.title, q) AS title, ts_headline(doc_data.description, q) AS description, doc_groups.groupname, doc_data.title||$1||description AS full_string_agg, doc_data_idx.vectors FROM doc_data, doc_groups, doc_data_idx, to_tsquery($2) AS q WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.docid = doc_data_idx.docid AND (vectors @@ to_tsquery($2)',
+					'SELECT x.* FROM (SELECT doc_data.docid, doc_data.filename, ts_headline(doc_data.title, q) AS title, ts_headline(doc_data.description, q) AS description, doc_groups.groupname, doc_data.title||$1||description AS full_string_agg, doc_data_idx.vectors, groups.group_name as project_name FROM groups, doc_data, doc_groups, doc_data_idx, to_tsquery($2) AS q WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.group_id = groups.group_id AND doc_data.docid = doc_data_idx.docid AND (vectors @@ to_tsquery($2))',
 					array ($this->field_separator, $words));
 		} else {
 			$qpa = db_construct_qpa(false,
-					'SELECT x.* FROM (SELECT doc_data.docid, ts_headline(doc_data.filename, q) AS filename, ts_headline(doc_data.title, q) AS title, ts_headline(doc_data.description, q) AS description, doc_groups.groupname, doc_data.title||$1||description||$1||filename AS full_string_agg, doc_data_words_idx.vectors FROM doc_data, doc_groups, doc_data_words_idx, to_tsquery($2) AS q WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.docid = doc_data_words_idx.docid AND (vectors @@ to_tsquery($2)',
+					'SELECT x.* FROM (SELECT doc_data.docid, ts_headline(doc_data.filename, q) AS filename, ts_headline(doc_data.title, q) AS title, ts_headline(doc_data.description, q) AS description, doc_groups.groupname, doc_data.title||$1||description||$1||filename AS full_string_agg, doc_data_words_idx.vectors, groups.group_name as project_name FROM groups, doc_data, doc_groups, doc_data_words_idx, to_tsquery($2) AS q WHERE doc_data.doc_group = doc_groups.doc_group AND doc_data.group_id = groups.group_id AND doc_data.docid = doc_data_words_idx.docid AND (vectors @@ to_tsquery($2))',
 					array ($this->field_separator, $words));
 		}
-		$qpa = db_construct_qpa($qpa,
-					 ') AND doc_data.group_id = $1',
-					 array ($group_id)) ;
-		if ($this->sections != SEARCH__ALL_SECTIONS) {
-			$qpa = db_construct_qpa($qpa,
-						 ' AND doc_groups.doc_group = ANY ($1)',
-						 array( db_int_array_to_any_clause ($this->sections))) ;
-		}
-		if ($this->showNonPublic) {
-			$qpa = db_construct_qpa($qpa,
-						 ' AND doc_data.stateid IN (1, 4, 5)') ;
-		} else {
-			$qpa = db_construct_qpa($qpa,
-						 ' AND doc_data.stateid = 1') ;
-		}
+		$qpa = $this->addCommonQPA($qpa);
 
-		if (isset($options['date_begin']) && !isset($options['date_end'])) {
-			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate >= $1', array($options['date_begin']));
-		} elseif (!isset($options['date_begin']) && isset($options['date_end'])) {
-			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate <= $1', array($options['date_end']));
-		} elseif (isset($options['date_begin']) && isset($options['date_end'])) {
-			$qpa = db_construct_qpa($qpa, ' AND doc_data.createdate between $1 and $2', array($options['date_begin'], $$options['date_end']));
-		}
-
-		$qpa = db_construct_qpa($qpa,
-					 ') AS x ') ;
+		$qpa = db_construct_qpa($qpa, ') AS x ') ;
 		if (count($this->phrases)) {
 			$qpa = db_construct_qpa($qpa, 'WHERE ') ;
 			$qpa = $this->addMatchCondition($qpa, 'full_string_agg');
diff --git a/src/www/search/include/renderers/DocsAllHtmlSearchRenderer.class.php b/src/www/search/include/renderers/DocsAllHtmlSearchRenderer.class.php
index 10365e6..bfd2c21 100644
--- a/src/www/search/include/renderers/DocsAllHtmlSearchRenderer.class.php
+++ b/src/www/search/include/renderers/DocsAllHtmlSearchRenderer.class.php
@@ -4,8 +4,8 @@
  *
  * Copyright 2004 (c) Dominik Haas, GForge Team
  * Copyright 2011, Franck Villaume - Capgemini
- * Copyright 2013,2014 Franck Villaume - TrivialDev
  * Copyright 2013, French Ministry of National Education
+ * Copyright 2013,2015 Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -25,7 +25,7 @@
  */
 
 require_once $gfwww.'search/include/renderers/HtmlSearchRenderer.class.php';
-require_once $gfcommon.'search/DocsAllSearchQuery.class.php';
+require_once $gfcommon.'search/DocsSearchQuery.class.php';
 require_once $gfcommon.'docman/Document.class.php';
 
 class DocsAllHtmlSearchRenderer extends HtmlSearchRenderer {
@@ -40,20 +40,20 @@ class DocsAllHtmlSearchRenderer extends HtmlSearchRenderer {
 	 *
 	 */
 	function DocsAllHtmlSearchRenderer($words, $offset, $isExact, $sections = SEARCH__ALL_SECTIONS) {
-		$parametersValues 	= array();
+		$groupIdValidArr = array();
 
 		if (session_loggedin()) {
 			$u =& session_get_user();
 			$listGroups = $u->getGroups();
 			if (count($listGroups) > 0) {
 				foreach ($listGroups as $group) {
-					$userIsGroupMember = forge_check_perm('docman', $group->getID(), 'read');
-					$parametersValues[$group->getID()]=$userIsGroupMember;
+					if (forge_check_perm('docman', $group->getID(), 'read')) {
+						$groupIdValidArr[] = $group->getID();
+					}
 				}
 			}
 		}
-
-		$searchQuery = new DocsAllSearchQuery($words, $offset, $isExact , $sections, $parametersValues);
+		$searchQuery = new DocsSearchQuery($words, $offset, $isExact, $groupIdValidArr, $sections);
 		$this->HtmlSearchRenderer(SEARCH__TYPE_IS_ALLDOCS, $words, $isExact, $searchQuery);
 		$this->tableHeaders = array(
 			_('Project'),
@@ -86,10 +86,6 @@ class DocsAllHtmlSearchRenderer extends HtmlSearchRenderer {
 
 		$rowColor = 0;
 		for($i = 0; $i < $rowsCount; $i++) {
-			//section changed
-			if(!forge_check_perm('docman', db_result($result, $i, 'project_name'), 'read')) {
-				continue;
-			}
 			$currentDocGroup = db_result($result, $i, 'project_name');
 			$currentDocGroupObject = group_get_object_by_publicname($currentDocGroup);
 			if ($lastDocGroup != $currentDocGroup) {
diff --git a/src/www/search/include/renderers/DocsHtmlSearchRenderer.class.php b/src/www/search/include/renderers/DocsHtmlSearchRenderer.class.php
index 78be225..c303d1d 100644
--- a/src/www/search/include/renderers/DocsHtmlSearchRenderer.class.php
+++ b/src/www/search/include/renderers/DocsHtmlSearchRenderer.class.php
@@ -44,7 +44,7 @@ class DocsHtmlSearchRenderer extends HtmlGroupSearchRenderer {
 
 		$userIsGroupMember = $this->isGroupMember($groupId);
 
-		$searchQuery = new DocsSearchQuery($words, $offset, $isExact, $groupId, $sections, $userIsGroupMember, $rowsPerPage, $options);
+		$searchQuery = new DocsSearchQuery($words, $offset, $isExact, array($groupId), $sections, $userIsGroupMember, $rowsPerPage, $options);
 
 		$this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_DOCS, $words, $isExact, $searchQuery, $groupId, 'docman');
 

-----------------------------------------------------------------------

Summary of changes:
 src/common/search/DocsAllSearchQuery.class.php     |  95 ------------------
 src/common/search/DocsSearchQuery.class.php        | 107 +++++++++------------
 .../renderers/DocsAllHtmlSearchRenderer.class.php  |  18 ++--
 .../renderers/DocsHtmlSearchRenderer.class.php     |   2 +-
 4 files changed, 56 insertions(+), 166 deletions(-)
 delete mode 100644 src/common/search/DocsAllSearchQuery.class.php


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list