[evolvis-commits] r17646: - Added advanced_search library

messer at evolvis.org messer at evolvis.org
Fri Oct 28 17:41:32 CEST 2011


Author: messer
Date: 2011-10-28 17:41:32 +0200 (Fri, 28 Oct 2011)
New Revision: 17646

Added:
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASInputAnalyzer.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASToken.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASTokenizer.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/EASToken.enum.php
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/FusionForgeDFIProvider.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/IDFIProvider.interface.php
Log:
- Added advanced_search library

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASInputAnalyzer.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASInputAnalyzer.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASInputAnalyzer.class.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,76 @@
+<?php
+
+/**
+ * The ASInputAnalyzer is able to analyze the current input and can
+ * return the next possible string identifier of a token in the current
+ * input. This can be used to give the user some feedback about their
+ * search query entered.
+ * 
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+require_once "ASTokenizer.class.php";
+
+class ASInputAnalyzer {
+    protected $DFIProvider = null;
+
+    public function analyzeInput($input, $params) {
+        ////Use the tokenizer to generate tokens.
+        $result = array();
+        $tokens = ASTokenizer::tokenize($input, $params);
+        $tokenCount = count($tokens);
+        $lastToken = end($tokens);
+        $forelastToken = $tokens[$tokenCount - 2];
+        
+		$dfiList = $this->DFIProvider->getDFIList($params);
+		
+        if(empty($tokens)) {
+        	//There are no tokens yet. Just print out the DFI List
+        	foreach($dfiList as $curDFI) {
+                $result[] = $curDFI[0];
+            }
+        }
+        else {
+        	//Token list is not empty. Check if the first token is a data token. If yes, print out DFIs again.
+        	if($tokens[0]->getType() == EASToken::AS_DATA) {
+        		foreach($dfiList as $curDFI) {
+        			$result[] = $curDFI[0];
+        		}
+        	}
+        	else {
+        		//All Special cases have been tested. Now check for the next possible
+        		//Tokens.
+        		//If we got a DFI token last, the next token has to be an operator
+        		if($forelastToken->getType() == EASToken::AS_DFI) {
+        			$result = array('equals', 'not', 'like', 'greater', 'less');
+        		}
+        		else if($forelastToken->getType() == EASToken::AS_OP_EQUALS ||
+        				$forelastToken->getType() == EASToken::AS_OP_GREATER ||
+        				$forelastToken->getType() == EASToken::AS_OP_LESS ||
+        				$forelastToken->getType() == EASToken::AS_OP_LIKE ||
+        				$forelastToken->getType() == EASToken::AS_OP_NOT) {
+        			//Next should be an data field but we cant determine when this field is finished
+        			//so just give a hint for the next possible operators.
+        			foreach($dfiList as $curDFI) {
+        				$result = array('and', 'or');
+        			}
+        		}
+        		else if($forelastToken->getType() == EASToken::AS_OP_AND ||
+        		        $forelastToken->getType() == EASToken::AS_OP_OR) {
+        		        	//Print the DFI List
+        		        	foreach($dfiList as $curDFI) {
+        		        		$result[] = $curDFI[0];
+        		        	}	
+        		}
+        	}
+        }
+        return $result;
+    }
+
+    public function setDFIProvider($provider) {
+        $this->DFIProvider = $provider;
+    }
+
+}
+
+?>

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASToken.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASToken.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASToken.class.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+
+class ASToken {
+    protected $type;
+    protected $data;
+    
+    public function __construct($type, $data) {
+        $this->type = $type;
+        $this->data = $data;
+    }
+    public function getType() {
+        return $this->type;
+    }
+    
+    public function getData() {
+        return $this->data;
+    }
+    
+    public function setType($newType) {
+        $this->type = $newType;
+    }
+    
+    public function setData($data) {
+        $this->data = $data;
+    }
+}
+?>

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASTokenizer.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASTokenizer.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/ASTokenizer.class.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,114 @@
+<?php
+/**
+ * The Tokenizer converts an string into the correpsonding tokens.
+ * Not reckognized tokens are automatically deleted.
+ * 
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+
+require_once "EASToken.enum.php";
+require_once "ASToken.class.php";
+
+class ASTokenizer {
+	public static $DFIProvider = null;
+	
+    public static function tokenize($inputString, $params) {
+        $tokens       = array();
+        $wordList     = explode(' ', $inputString);
+        $curTerm      = '';
+        $dfiList      = AStokenizer::$DFIProvider->getSimpleDFIList($params);
+        
+        foreach($wordList as $curWord) {
+            //Check if it is one of the tokens
+            switch(strtoupper($curWord)) {
+                case 'EQUALS': {
+                    //Check if $curTerm is not empty. If it is not, add an DFI Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_EQUALS, null);
+                }break;
+                case 'NOT': {
+                    //Check if $curTerm is not empty. If it is not, add an DFI Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_NOT, null);
+                }break;
+                case 'LIKE': {
+                    //Check if $curTerm is not empty. If it is not, add an DFI Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_LIKE, null);
+                }break;
+                case 'GREATER': {
+                    //Check if $curTerm is not empty. If it is not, add an DFI Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_GREATER, null);
+                }break;
+                case 'LESS': {
+                    //Check if $curTerm is not empty. If it is not, add an DFI Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_LESS, null);
+                }break;
+                case 'AND': {
+                    //Check if $curTerm is not empty. If it is not, add an Data Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DATA, $curTerm);
+                        $curTerm = '';
+                    }
+                    $tokens[] = new ASToken(EASToken::AS_OP_AND, null);
+                }break;
+                case 'OR': {
+                    //Check if $curTerm is not empty. If it is not, add an Data Token.
+                    if($curTerm != '') {
+                        $tokens[] = new ASToken(EASToken::AS_DATA, $curTerm);
+                        $curTerm = '';
+                    }
+                    
+                    $tokens[] = new ASToken(EASToken::AS_OP_OR, null);
+                }break;
+                default: {
+                    if($curTerm != '') {
+                        $curTerm .= ' '.$curWord;
+                    }
+                    else
+                    {
+                        $curTerm .= $curWord;
+                    }
+                }break;
+            }
+            //Check if we found an DFI
+            if(in_array($curTerm, $dfiList))
+            {
+                $tokens[] = new ASToken(EASToken::AS_DFI, $curTerm);
+                $curTerm = '';
+            }
+        }   
+        
+        //If curTerm is not empty there is still a data token left to add.
+        if($curTerm != '') {
+            $tokens[] = new ASToken(EASToken::AS_DATA, $curTerm);
+            $curTerm = '';
+        }
+        
+        return $tokens;
+    }
+}
+?>

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/EASToken.enum.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/EASToken.enum.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/EASToken.enum.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Enumeration of Advanced Search tokens.
+ * 
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+
+final class EASToken {
+    const AS_DFI        = 0;
+    const AS_OP_EQUALS  = 1;
+    const AS_OP_LIKE    = 2;
+    const AS_OP_GREATER = 3;
+    const AS_OP_LESS    = 4;
+    const AS_OP_AND     = 5;
+    const AS_OP_OR      = 6;
+    const AS_OP_NOT     = 7;
+    const AS_DATA       = 8;
+}
+?>

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/FusionForgeDFIProvider.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/FusionForgeDFIProvider.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/FusionForgeDFIProvider.class.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+
+require_once "IDFIProvider.interface.php";
+require_once('www/env.inc.php');
+require_once $gfwww.'include/pre.php'; 
+class FusionForgeDFIProvider implements IDFIProvider {
+    /**
+     * Nothing todo for fusionforge. FusionForgeDFIs can be identified
+     * trough a view.
+     * 
+     * @param type $fileName the file in which this info is stored
+     * @param type $params extra parameters.
+     */
+    public function scanAll($params) {
+        /*$tracker_id = $params['tracker_id'];
+        
+        $sql = "SELECT field_name, alias FROM artifact_extra_field_list WHERE group_artifact_id = $1";
+        $result = db_query_params($sql, array($tracker_id));
+        
+        //Write the result into*/
+    }
+    
+    /**
+     * Return the available DFIs for a given tracker defined in
+     * $params.
+     * 
+     * @param array $params
+     */
+    public function getDFIList($params) {
+        $tracker_id = $params['tracker_id'];
+        $result     = array();
+        //$result     = array(array('ID', 'artifact_id'), array('Open Date', 'date'), array('Assigned To', 'assigned_to'), array('Creator', 'crated_by'));
+        
+        $sql = "SELECT field_name, alias FROM artifact_extra_field_list WHERE group_artifact_id = $1";
+        $dbRes = db_query_params($sql, array($tracker_id));
+        
+        while ($arr = db_fetch_array($dbRes)) {
+            if($arr['field_name'] == 'Relation between artifacts'){
+            	//Ignore this
+            }
+            else {
+        		$result[] = array($arr['field_name'], $arr['alias']);
+            }
+        }
+        
+        return $result;
+    }
+    
+    public function getSimpleDFIList($params) {
+    	$tracker_id = $params['tracker_id'];
+        $result     = array();
+        //$result     = array(array('ID', 'artifact_id'), array('Open Date', 'date'), array('Assigned To', 'assigned_to'), array('Creator', 'crated_by'));
+        
+        $sql = "SELECT field_name FROM artifact_extra_field_list WHERE group_artifact_id = $1";
+        $dbRes = db_query_params($sql, array($tracker_id));
+        
+        while ($arr = db_fetch_array($dbRes)) {
+            if($arr['field_name'] == 'Relation between artifacts'){
+            	//Ignore this
+            }
+            else {
+        		$result[] = $arr['field_name'];
+            }
+        }
+        
+        return $result;
+    }
+}
+?>

Added: trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/IDFIProvider.interface.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/IDFIProvider.interface.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/advanced_search/IDFIProvider.interface.php	2011-10-28 15:41:32 UTC (rev 17646)
@@ -0,0 +1,27 @@
+<?php
+/**
+ * This interface is used to give the user of this library the possibility to
+ * define his own DFIs. This interface has to be reimplement per application.
+ * 
+ * Copyright (c) 2011
+ *      Mike Esser <m.esser at tarent.de>
+ */
+
+interface IDFIProvider {
+    /**
+     * This function scans for available DFIs. It generates
+     * a file in which the current available DFIs are stored.
+     * 
+     * @param array list of parameters.
+     */
+    public function scanAll($params);
+    /**
+     * Returns all available DFIs.
+     */
+    public function getDFIList($params);
+    /**
+     * Returns a simplified DFI List. This excludes aliases!
+     */
+    public function getSimpleDFIList($params);
+}
+?>



More information about the evolvis-commits mailing list