fix search
This commit is contained in:
144
config.php
144
config.php
@@ -2620,7 +2620,6 @@ class SearchEngine extends PhpObject
|
||||
private $iLevelMax;
|
||||
private $asItemRanks;
|
||||
private $asItemInfos;
|
||||
private $asCodeInfos;
|
||||
private $asUserInfos;
|
||||
|
||||
//Constants
|
||||
@@ -2634,7 +2633,6 @@ class SearchEngine extends PhpObject
|
||||
$this->asWords = $this->setWords('');
|
||||
$this->asItemRanks = array();
|
||||
$this->asItemInfos = array();
|
||||
$this->asCodeInfos = array();
|
||||
$this->asUserInfos = array();
|
||||
}
|
||||
|
||||
@@ -2679,6 +2677,48 @@ class SearchEngine extends PhpObject
|
||||
$this->iLevelMax = count($this->asWords);
|
||||
$this->setResults();
|
||||
}
|
||||
|
||||
private function setItemInfo($iSearchId, $iItemType, $iItemId)
|
||||
{
|
||||
if(!array_key_exists($iSearchId, $this->asItemInfos))
|
||||
{
|
||||
$this->asItemInfos[$iSearchId] = array('type'=>$iItemType, 'id_item'=>$iItemId);
|
||||
switch($iItemType)
|
||||
{
|
||||
case Databap::CODE_TYPE:
|
||||
$asItemInfo = $this->oMySql->selectRow
|
||||
(
|
||||
MySqlManager::CODE_TABLE,
|
||||
$iItemId,
|
||||
array(MySqlManager::getId(MySqlManager::USER_TABLE), 'description', 'led')
|
||||
);
|
||||
break;
|
||||
case Databap::PROC_TYPE:
|
||||
$asItemInfo = $this->oMySql->selectRow
|
||||
(
|
||||
MySqlManager::PROC_TABLE,
|
||||
$iItemId,
|
||||
array(MySqlManager::getId(MySqlManager::USER_TABLE), 'title AS description', 'led')
|
||||
);
|
||||
break;
|
||||
case Databap::ART_TYPE:
|
||||
$asItemInfo = $this->oMySql->selectRow
|
||||
(
|
||||
MySqlManager::ART_TABLE,
|
||||
$iItemId,
|
||||
array('first_name', 'last_name', 'title AS description', 'led')
|
||||
);
|
||||
$asItemInfo[MySqlManager::getId(MySqlManager::USER_TABLE)] = 0;
|
||||
break;
|
||||
}
|
||||
$this->asItemInfos[$iSearchId] += $asItemInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private function getItemInfo($iSearchId, $sInfoName)
|
||||
{
|
||||
return array_key_exists($iSearchId, $this->asItemInfos)?$this->asItemInfos[$iSearchId][$sInfoName]:false;
|
||||
}
|
||||
|
||||
private function setResults()
|
||||
{
|
||||
@@ -2698,29 +2738,23 @@ class SearchEngine extends PhpObject
|
||||
$this->oMySql->cleanSql($asSequence);
|
||||
|
||||
//$sRegExp = implode('(.{0,2})', $asSequence);
|
||||
$sRegExp = implode(' ?', $asSequence);
|
||||
$sRegExp = implode(self::KEYWORDS_SEPARATOR.'?', $asSequence);
|
||||
|
||||
//TODO replace with selectRow()
|
||||
$sQuery = "SELECT id_search, id_item, type FROM searchs WHERE keywords REGEXP '{$sRegExp}'";
|
||||
|
||||
//search sequence
|
||||
$asRows = $this->oMySql->getArrayQuery($sQuery, true);
|
||||
foreach($asRows as $asRow)
|
||||
$asItems = $this->oMySql->getArrayQuery($sQuery, true);
|
||||
foreach($asItems as $asItem)
|
||||
{
|
||||
$iItemId = $asRow['id_item'];
|
||||
unset($asRow['id_item']);
|
||||
$iSearchId = $asItem['id_search'];
|
||||
$iItemId = $asItem['id_item'];;
|
||||
$iItemType = $asItem['type'];
|
||||
|
||||
//TODO switch case type
|
||||
switch($asRow['type'])
|
||||
{
|
||||
case Databap::CODE_TYPE:
|
||||
$this->setCodeInfo($iItemId);
|
||||
$this->setUserInfo($this->getCodeInfo($iItemId, MySqlManager::getId(MySqlManager::USER_TABLE)));
|
||||
break;
|
||||
}
|
||||
$this->incItemRank($iSearchId, $iLevel);
|
||||
|
||||
$this->asItemInfos[$iItemId] = $asRow;
|
||||
$this->incItemRank($iItemId, $iLevel);
|
||||
$this->setItemInfo($iSearchId, $iItemType, $iItemId);
|
||||
$this->setUserInfo($this->getItemInfo($iSearchId, MySqlManager::getId(MySqlManager::USER_TABLE)));
|
||||
}
|
||||
$iIndex++;
|
||||
}
|
||||
@@ -2734,71 +2768,37 @@ class SearchEngine extends PhpObject
|
||||
|
||||
//Mixing info
|
||||
arsort($this->asItemRanks);
|
||||
foreach($this->asItemRanks as $iItemId=>$iRank)
|
||||
foreach($this->asItemRanks as $iSearchId=>$iRank)
|
||||
{
|
||||
switch($this->asItemInfos[$iItemId]['type'])
|
||||
{
|
||||
case Databap::CODE_TYPE:
|
||||
//$asRow['code'] = $this->formatCode($asRow['code'], $sRegExp);
|
||||
break;
|
||||
case Databap::PROC_TYPE:
|
||||
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
/* TODO Customized item preview
|
||||
//code
|
||||
$iUserId = $this->getCodeInfo($iItemId, MySqlManager::getId(MySqlManager::USER_TABLE));
|
||||
/* TODO
|
||||
$sCodeLines = implode("\n...\n", $this->getCodeInfo($iItemId, 'code'));
|
||||
$sCodeLines = implode("\n...\n", $this->getCodeInfo($iItemId, 'code'));
|
||||
$oCode = new Reader($sCodeLines);
|
||||
$sCodeLines = $oCode->getColoredCode();
|
||||
*/
|
||||
$sCodeLines = '';
|
||||
$asResult[$iItemId] = array('id_code'=>$iItemId,
|
||||
'code'=>$sCodeLines,
|
||||
'description'=>$this->getCodeInfo($iItemId, 'description'),
|
||||
'name'=>Databap::getNameFormat($this->getUserInfo($iUserId, 'first_name'), $this->getUserInfo($iUserId, 'last_name')),
|
||||
'company'=>Databap::getCompanyFormat($this->getUserInfo($iUserId, 'company')),
|
||||
'led'=>Databap::getDateFormat($this->getCodeInfo($iItemId, 'led')));
|
||||
*/
|
||||
|
||||
$iUserId = $this->getItemInfo($iSearchId, MySqlManager::getId(MySqlManager::USER_TABLE));
|
||||
$sFirstName = $this->getUserInfo($iUserId, 'first_name')?$this->getUserInfo($iUserId, 'first_name'):$this->getItemInfo($iSearchId, 'first_name');
|
||||
$sLastName = $this->getUserInfo($iUserId, 'last_name')?$this->getUserInfo($iUserId, 'last_name'):$this->getItemInfo($iSearchId, 'last_name');
|
||||
$sCompany = $this->getUserInfo($iUserId, 'company')?$this->getUserInfo($iUserId, 'company'):'SAP';
|
||||
$asResult[] = array('id_item'=>$this->getItemInfo($iSearchId, 'id_item'),
|
||||
'type'=>$this->getItemInfo($iSearchId, 'type'),
|
||||
'description'=>$this->getItemInfo($iSearchId, 'description'),
|
||||
'name'=>Databap::getNameFormat($sFirstName, $sLastName),
|
||||
'company'=>Databap::getCompanyFormat($sCompany),
|
||||
'led'=>Databap::getDateFormat($this->getItemInfo($iSearchId, 'led')));
|
||||
}
|
||||
|
||||
return $asResult;
|
||||
}
|
||||
|
||||
private function getCodeInfo($iCodeId, $sInfoName)
|
||||
{
|
||||
return $this->asCodeInfos[$iCodeId][$sInfoName];
|
||||
}
|
||||
|
||||
private function getUserInfo($iUserId, $sInfoName)
|
||||
{
|
||||
return $this->asUserInfos[$iUserId][$sInfoName];
|
||||
}
|
||||
|
||||
private function setCodeInfo($iCodeId)
|
||||
{
|
||||
if(!array_key_exists($iCodeId, $this->asCodeInfos))
|
||||
{
|
||||
$this->asCodeInfos[$iCodeId] = $this->oMySql->selectRow
|
||||
(
|
||||
MySqlManager::CODE_TABLE,
|
||||
$iCodeId,
|
||||
array(MySqlManager::getId(MySqlManager::USER_TABLE), 'description', 'led')
|
||||
);
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
$this->asCodeInfos[$iCodeId]['code'] = array_unique(array_merge($this->asCodeInfos[$iCodeId]['code'], $asInfos['code']));
|
||||
}
|
||||
*/
|
||||
return array_key_exists($iUserId, $this->asUserInfos)?$this->asUserInfos[$iUserId][$sInfoName]:false;
|
||||
}
|
||||
|
||||
private function setUserInfo($iUserId)
|
||||
{
|
||||
if(!array_key_exists($iUserId, $this->asUserInfos))
|
||||
if(!array_key_exists($iUserId, $this->asUserInfos) && $iUserId > 0)
|
||||
{
|
||||
$sCompanyIdCol = MySqlManager::getId(MySqlManager::COMP_TABLE);
|
||||
$this->asUserInfos[$iUserId] = $this->oMySql->selectRow
|
||||
@@ -2813,15 +2813,15 @@ class SearchEngine extends PhpObject
|
||||
}
|
||||
}
|
||||
|
||||
private function incItemRank($iItemId, $iRank)
|
||||
private function incItemRank($iSearchId, $iRank)
|
||||
{
|
||||
if(array_key_exists($iItemId, $this->asItemRanks))
|
||||
if(array_key_exists($iSearchId, $this->asItemRanks))
|
||||
{
|
||||
$this->asItemRanks[$iItemId] += $iRank;
|
||||
$this->asItemRanks[$iSearchId] += $iRank;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->asItemRanks[$iItemId] = $iRank;
|
||||
$this->asItemRanks[$iSearchId] = $iRank;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user