fix search

This commit is contained in:
2013-09-23 00:02:31 +02:00
parent 7624861623
commit 8b991096c4
23 changed files with 120 additions and 132 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/.project
/.buildpath

View File

@@ -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();
}
@@ -2680,6 +2678,48 @@ class SearchEngine extends PhpObject
$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()
{
if($this->iLevelMax>0)
@@ -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'));
$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;
}
}

0
jquery/fileuploader.js vendored Normal file → Executable file
View File

57
jquery/handler.js vendored Normal file → Executable file
View File

@@ -667,46 +667,19 @@ var databap =
databap.getInfo
(
'search',
function(asData)
function(asItems)
{
databap.$main.find('#code_container').empty();
databap.setCodeContainer
(
function()
$Container = databap.$main.find('#list_container');
$Container.empty();
if(asItems.length==0)
{
//display results
if(asData.length==0)
{
databap.$main.find('#code_container').append('Aucun résultat trouvé.');
$Container.append('Aucun résultat trouvé.');
}
else
{
$.each
(
asData,
function(id_code, code_info)
{
//append container
codeBoxId = databap.appendContainer('#code_container', id_code);
//link
$('#'+codeBoxId).click
(
function()
{
databap.vars.code = databap.getFirstElemId($(this).attr('id'));
databap.switchPage(databap.pages.read_code);
}
).addClass('clickable');
//append code to main and refresh id and return tag
var idTag = databap.appendCode('#'+codeBoxId, code_info);
}
);
for(iRankId in asItems) databap.appendItem(asItems[iRankId], $Container);
}
databap.addSuccessIcon();
}
);
},
{keywords:searchWords},
'json'
@@ -722,6 +695,24 @@ var databap =
//else debug('same words');
},
appendItem: function(asItemInfo, $Container)
{
//Filling up the item line
$verHtml = $(databap.consts.versionHtml);
$verHtml.find('#description').html(asItemInfo.description);
$verHtml.find('#author_name').html(asItemInfo.name);
$verHtml.find('#author_company').html(asItemInfo.company);
$verHtml.find('#led').html(asItemInfo.led);
//Link
var sItemLink = databap.getExternalLink(asItemInfo.type, asItemInfo.id_item);
$verHtml.find('#item_link').attr('href', sItemLink).attr('title', 'Lien vers '+sItemLink);
$verHtml = databap.setElemTags($verHtml, asItemInfo.id_item, false, asItemInfo.type);
//Display
$verHtml.hide().appendTo(databap.getMainElem('#list_container')).slideDown('fast');
},
getCodeLink: function(code)
{
return databap.getExternalLink('code', code);

0
jquery/jquery-1.4.4.min.js vendored Normal file → Executable file
View File

0
jquery/jquery-1.6.1.min.js vendored Normal file → Executable file
View File

0
jquery/jquery.min.js vendored Normal file → Executable file
View File

0
jquery/resize.js vendored Normal file → Executable file
View File

0
jquery/tinyscrollbar.js vendored Normal file → Executable file
View File

0
masks/add_code.html Normal file → Executable file
View File

0
masks/chat.html Normal file → Executable file
View File

0
masks/code_block.html Normal file → Executable file
View File

0
masks/doc.html Normal file → Executable file
View File

0
masks/error.html Normal file → Executable file
View File

0
masks/index.html Normal file → Executable file
View File

36
masks/list.html Normal file → Executable file
View File

@@ -10,7 +10,19 @@ databap.pageInit = function()
//TODO : to be replaced by tinyscrollbar
databap.$main.css('overflow', 'auto');
databap.getInfo('list', function(items){buildList(items);}, {}, 'json');
databap.getInfo
(
'list',
function(items)
{
buildList(items);
//Init's end
databap.setInitEnd(true);
},
{},
'json'
);
};
function buildList(asAllItems)
@@ -21,26 +33,10 @@ function buildList(asAllItems)
{
for(iItemId in asAllItems[sType])
{
asItemInfo = asAllItems[sType][iItemId];
//Filling up the item line
$verHtml = $(databap.consts.versionHtml);
$verHtml.find('#description').html(asItemInfo.description);
$verHtml.find('#author_name').html(asItemInfo.name);
$verHtml.find('#author_company').html(asItemInfo.company);
$verHtml.find('#led').html(asItemInfo.led);
//Link
var sItemLink = databap.getExternalLink(sType, iItemId);
$verHtml.find('#item_link').attr('href', sItemLink).attr('title', 'Lien vers '+sItemLink);
$verHtml = databap.setElemTags($verHtml, iItemId, false, sType);
//Display
$verHtml.hide().appendTo(databap.getMainElem('#list_container')).slideDown('fast');
asAllItems[sType][iItemId]['type'] = sType;
asAllItems[sType][iItemId]['id_item'] = iItemId;
databap.appendItem(asAllItems[sType][iItemId], databap.getMainElem('#list_container'));
}
}
//Init's end
databap.setInitEnd(true);
}
</script>

0
masks/logon.html Normal file → Executable file
View File

0
masks/options.html Normal file → Executable file
View File

0
masks/procedure.html Normal file → Executable file
View File

0
masks/profile.html Normal file → Executable file
View File

0
masks/read_code.html Normal file → Executable file
View File

2
masks/search.html Normal file → Executable file
View File

@@ -2,7 +2,7 @@
<div class="h1_wrap">
<h1 class="round"><span>Recherche</span></h1>
</div>
<div id="code_container"></div>
<div id="list_container" class="standalone"></div>
</div>
<script type="text/javascript">
databap.pageInit = function()

0
masks/welcome.html Normal file → Executable file
View File