diff --git a/core/expression.class.inc.php b/core/expression.class.inc.php
index a4b696813..13e7d9b5a 100644
--- a/core/expression.class.inc.php
+++ b/core/expression.class.inc.php
@@ -682,6 +682,33 @@ class CharConcatExpression extends Expression
}
}
+
+class CharConcatWSExpression extends CharConcatExpression
+{
+ protected $m_separator;
+
+ public function __construct($separator, $aExpressions)
+ {
+ $this->m_separator = $separator;
+ parent::__construct($aExpressions);
+ }
+
+ // recursive rendering
+ public function Render(&$aArgs = null, $bRetrofitParams = false)
+ {
+ $aRes = array();
+ foreach ($this->m_aExpressions as $oExpr)
+ {
+ $sCol = $oExpr->Render($aArgs, $bRetrofitParams);
+ // Concat will be globally NULL if one single argument is null !
+ $aRes[] = "COALESCE($sCol, '')";
+ }
+ $sSep = CMDBSource::Quote($this->m_separator);
+ return "CAST(CONCAT_WS($sSep, ".implode(', ', $aRes).") AS CHAR)";
+ }
+}
+
+
class QueryBuilderExpressions
{
protected $m_oConditionExpr;
diff --git a/core/metamodel.class.php b/core/metamodel.class.php
index 9ff9b836c..b9ae19333 100644
--- a/core/metamodel.class.php
+++ b/core/metamodel.class.php
@@ -2016,6 +2016,26 @@ abstract class MetaModel
$oQBExpr->AddSelect($sClassAlias.$sAttCode.$sColId, new FieldExpression($sAttCode.$sColId, $sClassAlias));
}
}
+
+ // Transform the full text condition into additional condition expression
+ $aFullText = $oFilter->GetCriteria_FullText();
+ if (count($aFullText) > 0)
+ {
+ $aFullTextFields = array();
+ foreach (self::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
+ {
+ if (!$oAttDef->IsScalar()) continue;
+ if ($oAttDef->IsExternalKey()) continue;
+ $aFullTextFields[] = new FieldExpression($sAttCode, $sClassAlias);
+ }
+ $oTextFields = new CharConcatWSExpression(' ', $aFullTextFields);
+
+ foreach($aFullText as $sFTNeedle)
+ {
+ $oNewCond = new BinaryExpression($oTextFields, 'LIKE', new ScalarExpression("%$sFTNeedle%"));
+ $oQBExpr->AddCondition($oNewCond);
+ }
+ }
}
$aExpectedAtts = array(); // array of (attcode => fieldexpression)
@@ -2281,22 +2301,9 @@ abstract class MetaModel
}
}
- // #@# todo - See what a full text search condition should be
- // 2 - WHERE / Full text search condition
- //
- if ($bIsOnQueriedClass)
- {
- $aFullText = $oFilter->GetCriteria_FullText();
- }
- else
- {
- // Pourquoi ???
- $aFullText = array();
- }
-
// 3 - The whole stuff, for this table only
//
- $oSelectBase = new SQLQuery($sTable, $sTableAlias, array(), $aFullText, $bIsOnQueriedClass, $aUpdateValues, $oSelectedIdField);
+ $oSelectBase = new SQLQuery($sTable, $sTableAlias, array(), $bIsOnQueriedClass, $aUpdateValues, $oSelectedIdField);
// 4 - The external keys -> joins...
//
diff --git a/core/sqlquery.class.inc.php b/core/sqlquery.class.inc.php
index 8a2b26051..5dbe45603 100644
--- a/core/sqlquery.class.inc.php
+++ b/core/sqlquery.class.inc.php
@@ -42,13 +42,12 @@ class SQLQuery
private $m_sTableAlias = '';
private $m_aFields = array();
private $m_oConditionExpr = null;
- private $m_aFullTextNeedles = array();
private $m_bToDelete = true; // The current table must be listed for deletion ?
private $m_aValues = array(); // Values to set in case of an update query
private $m_oSelectedIdField = null;
private $m_aJoinSelects = array();
- public function __construct($sTable, $sTableAlias, $aFields, $aFullTextNeedles = array(), $bToDelete = true, $aValues = array(), $oSelectedIdField = null)
+ public function __construct($sTable, $sTableAlias, $aFields, $bToDelete = true, $aValues = array(), $oSelectedIdField = null)
{
// This check is not needed but for developping purposes
//if (!CMDBSource::IsTable($sTable))
@@ -64,7 +63,6 @@ class SQLQuery
$this->m_sTableAlias = $sTableAlias;
$this->m_aFields = $aFields;
$this->m_oConditionExpr = null;
- $this->m_aFullTextNeedles = $aFullTextNeedles;
$this->m_bToDelete = $bToDelete;
$this->m_aValues = $aValues;
$this->m_oSelectedIdField = $oSelectedIdField;
@@ -95,16 +93,6 @@ class SQLQuery
echo "$this->m_sTable$sFields
\n";
// #@# todo - display html of an expression tree
//$this->m_oConditionExpr->DisplayHtml()
- if (count($this->m_aFullTextNeedles) > 0)
- {
- echo "Full text criteria...
\n";
- echo "