From 8b991096c41d3e3ee679ec51dd45d7d2fbc20bcc Mon Sep 17 00:00:00 2001 From: franzz Date: Mon, 23 Sep 2013 00:02:31 +0200 Subject: [PATCH] fix search --- .gitignore | 1 + config.php | 144 ++++++++++++++++++------------------- jquery/fileuploader.js | 0 jquery/handler.js | 69 ++++++++---------- jquery/jquery-1.4.4.min.js | 0 jquery/jquery-1.6.1.min.js | 0 jquery/jquery.min.js | 0 jquery/resize.js | 0 jquery/tinyscrollbar.js | 0 masks/add_code.html | 0 masks/chat.html | 0 masks/code_block.html | 0 masks/doc.html | 0 masks/error.html | 0 masks/index.html | 0 masks/list.html | 36 +++++----- masks/logon.html | 0 masks/options.html | 0 masks/procedure.html | 0 masks/profile.html | 0 masks/read_code.html | 0 masks/search.html | 2 +- masks/welcome.html | 0 23 files changed, 120 insertions(+), 132 deletions(-) mode change 100644 => 100755 jquery/fileuploader.js mode change 100644 => 100755 jquery/handler.js mode change 100644 => 100755 jquery/jquery-1.4.4.min.js mode change 100644 => 100755 jquery/jquery-1.6.1.min.js mode change 100644 => 100755 jquery/jquery.min.js mode change 100644 => 100755 jquery/resize.js mode change 100644 => 100755 jquery/tinyscrollbar.js mode change 100644 => 100755 masks/add_code.html mode change 100644 => 100755 masks/chat.html mode change 100644 => 100755 masks/code_block.html mode change 100644 => 100755 masks/doc.html mode change 100644 => 100755 masks/error.html mode change 100644 => 100755 masks/index.html mode change 100644 => 100755 masks/list.html mode change 100644 => 100755 masks/logon.html mode change 100644 => 100755 masks/options.html mode change 100644 => 100755 masks/procedure.html mode change 100644 => 100755 masks/profile.html mode change 100644 => 100755 masks/read_code.html mode change 100644 => 100755 masks/search.html mode change 100644 => 100755 masks/welcome.html diff --git a/.gitignore b/.gitignore index d8fe4fa..e845e07 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.project +/.buildpath diff --git a/config.php b/config.php index e834305..a1d90d7 100755 --- a/config.php +++ b/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; } } diff --git a/jquery/fileuploader.js b/jquery/fileuploader.js old mode 100644 new mode 100755 diff --git a/jquery/handler.js b/jquery/handler.js old mode 100644 new mode 100755 index 1ee3e18..cf43493 --- a/jquery/handler.js +++ b/jquery/handler.js @@ -667,46 +667,19 @@ var databap = databap.getInfo ( 'search', - function(asData) + function(asItems) { - databap.$main.find('#code_container').empty(); - databap.setCodeContainer - ( - function() - { - //display results - if(asData.length==0) - { - databap.$main.find('#code_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); - } - ); - } - databap.addSuccessIcon(); - } - ); + $Container = databap.$main.find('#list_container'); + $Container.empty(); + if(asItems.length==0) + { + $Container.append('Aucun résultat trouvé.'); + } + else + { + 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); diff --git a/jquery/jquery-1.4.4.min.js b/jquery/jquery-1.4.4.min.js old mode 100644 new mode 100755 diff --git a/jquery/jquery-1.6.1.min.js b/jquery/jquery-1.6.1.min.js old mode 100644 new mode 100755 diff --git a/jquery/jquery.min.js b/jquery/jquery.min.js old mode 100644 new mode 100755 diff --git a/jquery/resize.js b/jquery/resize.js old mode 100644 new mode 100755 diff --git a/jquery/tinyscrollbar.js b/jquery/tinyscrollbar.js old mode 100644 new mode 100755 diff --git a/masks/add_code.html b/masks/add_code.html old mode 100644 new mode 100755 diff --git a/masks/chat.html b/masks/chat.html old mode 100644 new mode 100755 diff --git a/masks/code_block.html b/masks/code_block.html old mode 100644 new mode 100755 diff --git a/masks/doc.html b/masks/doc.html old mode 100644 new mode 100755 diff --git a/masks/error.html b/masks/error.html old mode 100644 new mode 100755 diff --git a/masks/index.html b/masks/index.html old mode 100644 new mode 100755 diff --git a/masks/list.html b/masks/list.html old mode 100644 new mode 100755 index 06a3351..4683b13 --- a/masks/list.html +++ b/masks/list.html @@ -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); } \ No newline at end of file diff --git a/masks/logon.html b/masks/logon.html old mode 100644 new mode 100755 diff --git a/masks/options.html b/masks/options.html old mode 100644 new mode 100755 diff --git a/masks/procedure.html b/masks/procedure.html old mode 100644 new mode 100755 diff --git a/masks/profile.html b/masks/profile.html old mode 100644 new mode 100755 diff --git a/masks/read_code.html b/masks/read_code.html old mode 100644 new mode 100755 diff --git a/masks/search.html b/masks/search.html old mode 100644 new mode 100755 index 9c7481b..dcbbe93 --- a/masks/search.html +++ b/masks/search.html @@ -2,7 +2,7 @@

Recherche

-
+