ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilSearch Class Reference

search More...

+ Collaboration diagram for ilSearch:

Public Member Functions

 ilSearch ($a_user_id=0, $a_read=false)
 Constructor public.
 setSearchString ($a_search_str)
 setCombination ($a_combination)
 setSearchFor ($a_search_for)
 setSearchIn ($a_search_in)
 setResult ($a_result)
 setSearchType ($a_type)
 setPerformUpdate ($a_value)
 setEmptySearch ($a_value)
 setMinWordLength ($a_min_word_length)
 getMinWordLength ()
 getUserId ()
 getSearchString ()
 getCombination ()
 getSearchFor ()
 getSearchIn ()
 getSearchInByType ($a_type)
 getResults ()
 getResultByType ($a_type)
 getSearchType ()
 getPerformUpdate ()
 getEmptySearch ()
 getNumberOfResults ()
 validate (&$message)
 performSearch ()
 __parseSearchString ()
 __updateDBResult ()
 __readDBResult ()
 __checkAccess ($a_results, $a_type)
 __validateResults ()
 __prepareWord ($a_word)

Data Fields

 $ilias
 $lng
 $rbacsystem
 $user_id
 $search_string
 $parsed_str
 $combination
 $min_word_length = 3
 $search_for
 $search_in
 $search_type
 $result
 $perform_update
 $read_db_result
 $allow_empty_search

Protected Member Functions

 performUserSearch ()
 perform a search for users
 performObjectSearch ($a_type)
 perform object search
 performRoleSearch ()
 initQueryParser ()
 init query parser

Protected Attributes

 $qp = null

Detailed Description

search

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id$

Definition at line 14 of file class.ilSearch.php.

Member Function Documentation

ilSearch::__checkAccess (   $a_results,
  $a_type 
)

Definition at line 349 of file class.ilSearch.php.

References $result.

Referenced by __validateResults().

{
global $ilAccess;
if (is_array($a_results))
{
foreach ($a_results as $result)
{
if($ilAccess->checkAccess('read','',$result['id']))
{
$checked_result[] = $result;
break;
}
}
}
return $checked_result ? $checked_result : array();
}

+ Here is the caller graph for this function:

ilSearch::__parseSearchString ( )

Definition at line 242 of file class.ilSearch.php.

References __prepareWord(), getCombination(), and getSearchString().

{
$tmp_arr = explode(" ",$this->getSearchString());
$this->parsed_str["and"] = $this->parsed_str["or"] = $this->parsed_str["not"] = array();
foreach ($tmp_arr as $word)
{
#$word = trim($word);
$word = $this->__prepareWord($word);
if ($word)
{
if (substr($word,0,1) == '+')
{
$this->parsed_str["all"][] = substr($word,1);
$this->parsed_str["and"][] = substr($word,1);
continue;
}
if (substr($word,0,1) == '-')
{
// better parsed_str["allmost_all"] ;-)
#$this->parsed_str["all"][] = substr($word,1);
$this->parsed_str["not"][] = substr($word,1);
continue;
}
if ($this->getCombination() == 'and')
{
$this->parsed_str["all"][] = $word;
$this->parsed_str["and"][] = $word;
continue;
}
if ($this->getCombination() == 'or')
{
$this->parsed_str["all"][] = $word;
$this->parsed_str["or"][] = $word;
continue;
}
}
}
}

+ Here is the call graph for this function:

ilSearch::__prepareWord (   $a_word)

Definition at line 457 of file class.ilSearch.php.

Referenced by __parseSearchString().

{
$word = trim($a_word);
if(!preg_match('/\*/',$word))
{
return '%'.$word.'%';
}
if(preg_match('/^\*/',$word))
{
return str_replace('*','%',$word);
}
else
{
return '% '.str_replace('*','%',$word);
}
}

+ Here is the caller graph for this function:

ilSearch::__readDBResult ( )

Definition at line 311 of file class.ilSearch.php.

References $query, $res, $row, __updateDBResult(), __validateResults(), DB_FETCHMODE_OBJECT, getUserId(), and setResult().

{
global $ilDB;
if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID and $this->read_db_result)
{
$query = "SELECT search_result FROM usr_search ".
"WHERE usr_id = ".$ilDB->quote($this->getUserId() ,'integer');
$res = $ilDB->query($query);
if ($res->numRows())
{
$this->setResult(unserialize(stripslashes($row->search_result)));
}
else
{
$this->setResult(array("usr" => array(),
"grp" => array(),
"lm" => array(),
"dbk" => array()));
}
}
else
{
$this->setResult(array("usr" => array(),
"grp" => array(),
"lm" => array(),
"dbk" => array()));
}
$this->__updateDBResult();
return true;
}

+ Here is the call graph for this function:

ilSearch::__updateDBResult ( )

Definition at line 285 of file class.ilSearch.php.

References getResults(), and getUserId().

Referenced by __readDBResult(), and performSearch().

{
global $ilDB;
if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID)
{
$ilDB->manipulate("DELETE FROM usr_search ".
"WHERE usr_id = ".$ilDB->quote($this->getUserId() ,'integer')." ".
"AND search_type = 0 ");
$ilDB->insert('usr_search',array(
'usr_id' => array('integer',$this->getUserId()),
'search_result' => array('clob',serialize($this->getResults())),
'checked' => array('clob',serialize(array())),
'failed' => array('clob',serialize(array())),
'page' => array('integer',0),
'search_type' => array('integer',0),
'query' => array('text',''),
'root' => array('integer',ROOT_FOLDER_ID)));
return true;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearch::__validateResults ( )

Definition at line 368 of file class.ilSearch.php.

References __checkAccess(), ilObjectFactory\getInstanceByObjId(), and setResult().

Referenced by __readDBResult(), and performSearch().

{
global $tree;
$new_result = array();
// check lm meta
$this->result['lm']['meta'] = $this->__checkAccess($this->result['lm']['meta'],'lm');
if(is_array($this->result['lm']['meta']))
{
foreach($this->result['lm']['meta'] as $data)
{
if($tree->isInTree($data['id']))
{
$new_result['lm']['meta'][] = $data;
}
}
}
$this->result['lm']['content'] = $this->__checkAccess($this->result['lm']['content'],'lm');
if(is_array($this->result['lm']['content']))
{
foreach($this->result['lm']['content'] as $data)
{
if($tree->isInTree($data['id']))
{
$new_result['lm']['content'][] = $data;
}
}
}
$this->result['dbk']['meta'] = $this->__checkAccess($this->result['dbk']['meta'],'dbk');
if(is_array($this->result['dbk']['meta']))
{
foreach($this->result['dbk']['meta'] as $data)
{
if($tree->isInTree($data['id']))
{
$new_result['dbk']['meta'][] = $data;
}
}
}
$this->result['dbk']['content'] = $this->__checkAccess($this->result['dbk']['content'],'dbk');
if(is_array($this->result['dbk']['content']))
{
foreach($this->result['dbk']['content'] as $data)
{
if($tree->isInTree($data['id']))
{
$new_result['dbk']['content'][] = $data;
}
}
}
$this->result['grp'] = $this->__checkAccess($this->result['grp'],'grp');
if(is_array($this->result['grp']))
{
foreach($this->result['grp'] as $data)
{
if($tree->isInTree($data['id']))
{
$new_result['grp'][] = $data;
}
}
}
if(is_array($this->result['usr']))
{
foreach($this->result['usr'] as $user)
{
if($tmp_obj =& ilObjectFactory::getInstanceByObjId($user['id'],false))
{
$new_result['usr'][] = $user;
}
}
}
if(is_array($this->result['role']))
{
foreach($this->result['role'] as $user)
{
if($tmp_obj =& ilObjectFactory::getInstanceByObjId($user['id'],false))
{
$new_result['role'][] = $user;
}
}
}
$this->setResult($new_result);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearch::getCombination ( )

Definition at line 115 of file class.ilSearch.php.

Referenced by __parseSearchString(), initQueryParser(), and performObjectSearch().

{
return $this->combination ? $this->combination : "or";
}

+ Here is the caller graph for this function:

ilSearch::getEmptySearch ( )

Definition at line 154 of file class.ilSearch.php.

References $allow_empty_search.

ilSearch::getMinWordLength ( )

Definition at line 101 of file class.ilSearch.php.

References $min_word_length.

Referenced by initQueryParser().

+ Here is the caller graph for this function:

ilSearch::getNumberOfResults ( )

Definition at line 161 of file class.ilSearch.php.

References getResultByType().

{
$number = count($this->getResultByType("usr")) + count($this->getResultByType("grp")) + count($this->getResultByType("role"));
$tmp_res = $this->getResultByType("dbk");
$number += count($tmp_res["meta"]) + count($tmp_res["content"]);
$tmp_res = $this->getResultByType("lm");
$number += count($tmp_res["meta"]) + count($tmp_res["content"]);
return $number;
}

+ Here is the call graph for this function:

ilSearch::getPerformUpdate ( )

Definition at line 150 of file class.ilSearch.php.

References $perform_update.

Referenced by performSearch().

{
}

+ Here is the caller graph for this function:

ilSearch::getResultByType (   $a_type)

Definition at line 142 of file class.ilSearch.php.

Referenced by getNumberOfResults().

{
return $this->result[$a_type] ? $this->result[$a_type] : array();
}

+ Here is the caller graph for this function:

ilSearch::getResults ( )

Definition at line 138 of file class.ilSearch.php.

Referenced by __updateDBResult().

{
return $this->result ? $this->result : array();
}

+ Here is the caller graph for this function:

ilSearch::getSearchFor ( )

Definition at line 119 of file class.ilSearch.php.

Referenced by performSearch().

{
return $this->search_for ? $this->search_for : array();
}

+ Here is the caller graph for this function:

ilSearch::getSearchIn ( )

Definition at line 123 of file class.ilSearch.php.

{
return $this->search_in ? $this->search_in : array();
}
ilSearch::getSearchInByType (   $a_type)

Definition at line 127 of file class.ilSearch.php.

{
if($a_type == 'lm' or $a_type == 'dbk')
{
return $this->search_in[$a_type];
}
else
{
return false;
}
}
ilSearch::getSearchString ( )

Definition at line 111 of file class.ilSearch.php.

References $search_string.

Referenced by __parseSearchString(), and initQueryParser().

{
}

+ Here is the caller graph for this function:

ilSearch::getSearchType ( )

Definition at line 146 of file class.ilSearch.php.

References $search_type.

{
}
ilSearch::getUserId ( )

Definition at line 107 of file class.ilSearch.php.

References $user_id.

Referenced by __readDBResult(), __updateDBResult(), and performUserSearch().

{
}

+ Here is the caller graph for this function:

ilSearch::ilSearch (   $a_user_id = 0,
  $a_read = false 
)

Constructor public.

Definition at line 43 of file class.ilSearch.php.

References $ilias, $lng, $rbacsystem, setEmptySearch(), and setPerformUpdate().

{
// Initiate variables
$this->ilias =& $ilias;
$this->lng =& $lng;
$this->lng->loadLanguageModule("search");
$this->rbacsystem =& $rbacsystem;
$this->user_id = $a_user_id;
$this->setPerformUpdate(true);
$this->setEmptySearch(false);
$this->read_db_result = $a_read;
// READ OLD SEARCH RESULTS FROM DATABASE
#$this->__readDBResult();
}

+ Here is the call graph for this function:

ilSearch::initQueryParser ( )
protected

init query parser

Returns

Definition at line 548 of file class.ilSearch.php.

References getCombination(), getMinWordLength(), getSearchString(), QP_COMBINATION_AND, and QP_COMBINATION_OR.

Referenced by performSearch(), and validate().

{
if($this->qp)
{
return true;
}
$this->qp = new ilQueryParser($this->getSearchString());
$this->qp->setCombination($this->getCombination() == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
$this->qp->setMinWordLength($this->getMinWordLength());
$this->qp->parse();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearch::performObjectSearch (   $a_type)
protected

perform object search

Returns

Definition at line 507 of file class.ilSearch.php.

References $res, and getCombination().

Referenced by performSearch().

{
include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
$object_search = new ilLikeObjectSearch($this->qp);
$object_search->setFilter(array($a_type));
$res = $object_search->performSearch();
$res->filter(ROOT_FOLDER_ID,$this->getCombination());
$counter = 0;
foreach($res->getResultIds() as $id)
{
$objs[$counter++]['id'] = $id;
}
return $objs ? $objs : array();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearch::performRoleSearch ( )
protected
Parameters
@return

Definition at line 528 of file class.ilSearch.php.

References $res.

Referenced by performSearch().

{
// Perform like search
include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
$object_search = new ilLikeObjectSearch($this->qp);
$object_search->setFilter(array('role'));
$res = $object_search->performSearch();
foreach($res->getEntries() as $id => $data)
{
$tmp['id'] = $id;
$roles[] = $tmp;
}
return $roles ? $roles : array();
}

+ Here is the caller graph for this function:

ilSearch::performSearch ( )

Definition at line 186 of file class.ilSearch.php.

References $ilBench, $result, __updateDBResult(), __validateResults(), getPerformUpdate(), getSearchFor(), initQueryParser(), performObjectSearch(), performRoleSearch(), performUserSearch(), and setResult().

{
global $objDefinition, $ilBench;
$ilBench->start("Search", "performSearch");
$this->initQueryParser();
$result = array("usr" => array(),
"grp" => array(),
"lm" => array(),
"dbk" => array(),
"role"=> array());
foreach($this->getSearchFor() as $obj_type)
{
switch($obj_type)
{
case "usr":
$result['usr'] = $this->performUserSearch();
break;
case "grp":
$result['grp'] = $this->performObjectSearch('grp');
break;
case "lm":
$result['lm'] = $this->performObjectSearch('lm');
break;
case "dbk":
$result['dbk'] = $this->performObjectSearch('dbk');
break;
case "role":
$result['role'] = $this->performRoleSearch();
break;
}
}
$this->setResult($result);
if ($this->getPerformUpdate())
{
$this->__updateDBResult();
}
$ilBench->stop("Search", "performSearch");
return true;
}

+ Here is the call graph for this function:

ilSearch::performUserSearch ( )
protected

perform a search for users

Returns

Definition at line 479 of file class.ilSearch.php.

References $res, ilObjectSearchFactory\_getUserSearchInstance(), and getUserId().

Referenced by performSearch().

{
include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
$res = new ilSearchResult($this->getUserId());
foreach(array("login","firstname","lastname","title",
"email","institution","street","city","zipcode","country","phone_home","fax") as $field)
{
$user_search->setFields(array($field));
$tmp_res = $user_search->performSearch();
$res->mergeEntries($tmp_res);
}
foreach($res->getEntries() as $id => $data)
{
$tmp['id'] = $id;
$users[] = $tmp;
}
return $users ? $users : array();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearch::setCombination (   $a_combination)

Definition at line 67 of file class.ilSearch.php.

{
// 'and' or 'or'
$this->combination = $a_combination;
}
ilSearch::setEmptySearch (   $a_value)

Definition at line 92 of file class.ilSearch.php.

Referenced by ilSearch().

{
$this->allow_empty_search = $a_value;
}

+ Here is the caller graph for this function:

ilSearch::setMinWordLength (   $a_min_word_length)

Definition at line 97 of file class.ilSearch.php.

{
$this->min_word_length = $a_min_word_length;
}
ilSearch::setPerformUpdate (   $a_value)

Definition at line 88 of file class.ilSearch.php.

Referenced by ilPaymentTrusteeGUI\__search(), ilPaymentStatisticGUI\__search(), ilObjPaymentSettingsGUI\__searchSP(), and ilSearch().

{
$this->perform_update = $a_value;
}

+ Here is the caller graph for this function:

ilSearch::setResult (   $a_result)

Definition at line 80 of file class.ilSearch.php.

Referenced by __readDBResult(), __validateResults(), and performSearch().

{
$this->result = $a_result;
}

+ Here is the caller graph for this function:

ilSearch::setSearchFor (   $a_search_for)

Definition at line 72 of file class.ilSearch.php.

{
$this->search_for = $a_search_for;
}
ilSearch::setSearchIn (   $a_search_in)

Definition at line 76 of file class.ilSearch.php.

{
$this->search_in = $a_search_in;
}
ilSearch::setSearchString (   $a_search_str)

Definition at line 63 of file class.ilSearch.php.

{
$this->search_string = trim($a_search_str);
}
ilSearch::setSearchType (   $a_type)

Definition at line 84 of file class.ilSearch.php.

{
$this->search_type = $a_type;
}
ilSearch::validate ( $message)

Definition at line 174 of file class.ilSearch.php.

References initQueryParser().

{
$this->initQueryParser();
if(!$this->qp->validate())
{
$message = $this->qp->getMessage();
return false;
}
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilSearch::$allow_empty_search

Definition at line 38 of file class.ilSearch.php.

Referenced by getEmptySearch().

ilSearch::$combination

Definition at line 29 of file class.ilSearch.php.

ilSearch::$ilias

Definition at line 23 of file class.ilSearch.php.

Referenced by ilSearch().

ilSearch::$lng

Definition at line 24 of file class.ilSearch.php.

Referenced by ilSearch().

ilSearch::$min_word_length = 3

Definition at line 30 of file class.ilSearch.php.

Referenced by getMinWordLength().

ilSearch::$parsed_str

Definition at line 28 of file class.ilSearch.php.

ilSearch::$perform_update

Definition at line 35 of file class.ilSearch.php.

Referenced by getPerformUpdate().

ilSearch::$qp = null
protected

Definition at line 16 of file class.ilSearch.php.

ilSearch::$rbacsystem

Definition at line 25 of file class.ilSearch.php.

Referenced by ilSearch().

ilSearch::$read_db_result

Definition at line 36 of file class.ilSearch.php.

ilSearch::$result

Definition at line 34 of file class.ilSearch.php.

Referenced by __checkAccess(), and performSearch().

ilSearch::$search_for

Definition at line 31 of file class.ilSearch.php.

ilSearch::$search_in

Definition at line 32 of file class.ilSearch.php.

ilSearch::$search_string

Definition at line 27 of file class.ilSearch.php.

Referenced by getSearchString().

ilSearch::$search_type

Definition at line 33 of file class.ilSearch.php.

Referenced by getSearchType().

ilSearch::$user_id

Definition at line 26 of file class.ilSearch.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: