瀏覽代碼

Implemented enhancement #130: keywords to narrow the scope of the global search

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1369 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 年之前
父節點
當前提交
ae4c9509b3
共有 3 個文件被更改,包括 43 次插入6 次删除
  1. 2 2
      application/itopwebpage.class.inc.php
  2. 13 3
      core/metamodel.class.php
  3. 28 1
      pages/UI.php

+ 2 - 2
application/itopwebpage.class.inc.php

@@ -582,7 +582,7 @@ EOF
             }
             echo "</style>\n";
         }
-		echo "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"./opensearch.xml.php\" />\n";
+		echo "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"".utils::GetAbsoluteUrlAppRoot()."opensearch.xml.php\" />\n";
         echo "</head>\n";
         echo "<body>\n";
 
@@ -606,7 +606,7 @@ EOF
 		}
 
 		// Render the text of the global search form
-		$sText = Utils::ReadParam('text', '');
+		$sText = htmlentities(utils::ReadParam('text', ''), ENT_QUOTES, 'UTF-8');
 		$sOnClick = "";
 		if (empty($sText))
 		{

+ 13 - 3
core/metamodel.class.php

@@ -310,13 +310,23 @@ abstract class MetaModel
 			return self::GetName($sClass);
 		}
 	}
-	final static public function GetClassFromLabel($sClassLabel)
+	final static public function GetClassFromLabel($sClassLabel, $bCaseSensitive = true)
 	{
 		foreach(self::GetClasses() as $sClass)
 		{
-			if (self::GetName($sClass) == $sClassLabel)
+			if ($bCaseSensitive)
 			{
-				return $sClass;
+				if (self::GetName($sClass) == $sClassLabel)
+				{
+					return $sClass;
+				}
+			}
+			else
+			{
+				if (strcasecmp(self::GetName($sClass), $sClassLabel) == 0)
+				{
+					return $sClass;
+				}				
 			}
 		}
 		return null;

+ 28 - 1
pages/UI.php

@@ -627,6 +627,22 @@ try
 				$iBlock = 0;
 				// Search in full text mode in all the classes
 				$aMatches = array();
+				$sClassName = '';
+				
+				// Check if a class name/label is supplied to limit the search
+				if (preg_match('/^(.+):(.+)$/', $sFullText, $aMatches))
+				{
+					$sClassName = $aMatches[1];
+					if (MetaModel::IsValidClass($sClassName))
+					{
+						$sFullText = $aMatches[2];
+					}
+					elseif ($sClassName = MetaModel::GetClassFromLabel($sClassName, false /* => not case sensitive */))
+					{
+						$sFullText = $aMatches[2];
+					}
+				}
+				
 				if (preg_match('/^"(.*)"$/', $sFullText, $aMatches))
 				{
 					// The text is surrounded by double-quotes, remove the quotes and treat it as one single expression
@@ -637,7 +653,18 @@ try
 					// Split the text on the blanks and treat this as a search for <word1> AND <word2> AND <word3>
 					$aFullTextNeedles = explode(' ', $sFullText);
 				}
-				foreach(MetaModel::GetClasses('searchable') as $sClassName)
+				
+				// Search is limited ot a given class, or not...
+				if (empty($sClassName))
+				{
+					$aSearchClasses = MetaModel::GetClasses('searchable');					
+				}
+				else
+				{
+					$aSearchClasses = MetaModel::EnumChildClasses($sClassName, ENUM_CHILD_CLASSES_ALL);
+				}
+			
+				foreach($aSearchClasses as $sClassName)
 				{
 					$oFilter = new DBObjectSearch($sClassName);
 					foreach($aFullTextNeedles as $sSearchText)