* Adjust code
This commit is contained in:
@@ -191,7 +191,7 @@ class search extends control
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = zget($this->lang->searchObjects, ($result['type'] == 'case' ? 'testcase' : $result['type']), $result['type']);
|
||||
$type = zget($this->lang->search->modules, ($result['type'] == 'case' ? 'testcase' : $result['type']), $result['type']);
|
||||
return $this->send(array('result' => 'unfinished', 'message' => sprintf($this->lang->search->buildResult, $type, $type, $result['count']), 'type' => $type, 'count' => $result['count'], 'next' => inlink('buildIndex', "type={$result['type']}&lastID={$result['lastID']}") ));
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,12 @@ class search extends control
|
||||
{
|
||||
$this->lang->admin->menu->search = "{$this->lang->search->common}|search|index";
|
||||
|
||||
$requirementIds = $this->dao->select('t1.id')->from(TABLE_SEARCHINDEX)->alias('t1')
|
||||
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.objectID = t2.id')
|
||||
->where('t1.objectType')->eq('story')
|
||||
->andWhere('t2.type')->eq('requirement')
|
||||
->fetchPairs('id');
|
||||
$this->dao->update(TABLE_SEARCHINDEX)->set('objectType')->eq('requirement')->where('id')->in($requirementIds)->exec();
|
||||
if(empty($words)) $words = $this->get->words;
|
||||
if(empty($words)) $words = $this->post->words;
|
||||
if(empty($words) and ($recTotal != 0 or $pageID != 1)) $words = $this->session->searchIngWord;
|
||||
@@ -233,7 +239,7 @@ class search extends control
|
||||
|
||||
if($words)
|
||||
{
|
||||
$typeCount = $this->search->getList($words, 'all', null, true);
|
||||
$typeCount = $this->search->getListCount($words);
|
||||
$typeList = array('all' => $this->lang->search->modules['all']);
|
||||
foreach($typeCount as $objectType => $count)
|
||||
{
|
||||
|
||||
@@ -95,8 +95,8 @@ $lang->search->modules['productplan'] = 'Plan';
|
||||
$lang->search->modules['program'] = 'Program';
|
||||
$lang->search->modules['project'] = 'Project';
|
||||
$lang->search->modules['execution'] = $lang->executionCommon;
|
||||
$lang->search->modules['story'] = 'Software Requirement';
|
||||
$lang->search->modules['requirement'] = 'User Requirement';
|
||||
$lang->search->modules['story'] = $lang->SRCommon;
|
||||
$lang->search->modules['requirement'] = $lang->URCommon;
|
||||
|
||||
$lang->search->objectTypeList['story'] = $lang->SRCommon;
|
||||
$lang->search->objectTypeList['requirement'] = $lang->URCommon;
|
||||
|
||||
@@ -95,8 +95,8 @@ $lang->search->modules['productplan'] = 'Plan';
|
||||
$lang->search->modules['program'] = 'Program';
|
||||
$lang->search->modules['project'] = 'Project';
|
||||
$lang->search->modules['execution'] = $lang->executionCommon;
|
||||
$lang->search->modules['story'] = 'Software Requirement';
|
||||
$lang->search->modules['requirement'] = 'User Requirement';
|
||||
$lang->search->modules['story'] = $lang->SRCommon;
|
||||
$lang->search->modules['requirement'] = $lang->URCommon;
|
||||
|
||||
$lang->search->objectTypeList['story'] = $lang->SRCommon;
|
||||
$lang->search->objectTypeList['requirement'] = $lang->URCommon;
|
||||
|
||||
@@ -95,8 +95,8 @@ $lang->search->modules['productplan'] = 'Plan';
|
||||
$lang->search->modules['program'] = 'Program';
|
||||
$lang->search->modules['project'] = 'Project';
|
||||
$lang->search->modules['execution'] = $lang->executionCommon;
|
||||
$lang->search->modules['story'] = 'Software Requirement';
|
||||
$lang->search->modules['requirement'] = 'User Requirement';
|
||||
$lang->search->modules['story'] = $lang->SRCommon;
|
||||
$lang->search->modules['requirement'] = $lang->URCommon;
|
||||
|
||||
$lang->search->objectTypeList['story'] = $lang->SRCommon;
|
||||
$lang->search->objectTypeList['requirement'] = $lang->URCommon;
|
||||
|
||||
@@ -95,8 +95,8 @@ $lang->search->modules['productplan'] = '计划';
|
||||
$lang->search->modules['program'] = '项目集';
|
||||
$lang->search->modules['project'] = '项目';
|
||||
$lang->search->modules['execution'] = $lang->executionCommon;
|
||||
$lang->search->modules['story'] = '研发需求';
|
||||
$lang->search->modules['requirement'] = '用户需求';
|
||||
$lang->search->modules['story'] = $lang->SRCommon;
|
||||
$lang->search->modules['requirement'] = $lang->URCommon;
|
||||
|
||||
$lang->search->objectTypeList['story'] = $lang->SRCommon;
|
||||
$lang->search->objectTypeList['requirement'] = $lang->URCommon;
|
||||
|
||||
+65
-16
@@ -585,16 +585,14 @@ class searchModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* get search results of keywords.
|
||||
* Get counts of keyword search results.
|
||||
*
|
||||
* @param string $keywords
|
||||
* @param string $type
|
||||
* @param object $pager
|
||||
* @param bool $getCount
|
||||
* @access public
|
||||
* @return array
|
||||
* @return void
|
||||
*/
|
||||
public function getList($keywords, $type, $pager = null, $getCount = false)
|
||||
public function getListCount($keywords, $type = 'all')
|
||||
{
|
||||
$spliter = $this->app->loadClass('spliter');
|
||||
$words = explode(' ', self::unify($keywords, ' '));
|
||||
@@ -638,18 +636,69 @@ class searchModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
if($getCount)
|
||||
$typeCount = $this->dao->select("objectType, count(*) as objectCount")
|
||||
->from(TABLE_SEARCHINDEX)
|
||||
->where("(MATCH(title,content) AGAINST('{$againstCond}' IN BOOLEAN MODE) >= 1 {$likeCondition})")
|
||||
->andWhere('vision')->eq($this->config->vision)
|
||||
->andWhere('objectType')->in($allowedObject)
|
||||
->andWhere('addedDate')->le(helper::now())
|
||||
->groupBy('objectType')
|
||||
->fetchPairs('objectType', 'objectCount');
|
||||
arsort($typeCount);
|
||||
return $typeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* get search results of keywords.
|
||||
*
|
||||
* @param string $keywords
|
||||
* @param string $type
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getList($keywords, $type, $pager = null)
|
||||
{
|
||||
$spliter = $this->app->loadClass('spliter');
|
||||
$words = explode(' ', self::unify($keywords, ' '));
|
||||
|
||||
$against = '';
|
||||
$againstCond = '';
|
||||
|
||||
foreach($words as $word)
|
||||
{
|
||||
$typeCount = $this->dao->select("objectType, count(*) as objectCount")
|
||||
->from(TABLE_SEARCHINDEX)
|
||||
->where("(MATCH(title,content) AGAINST('{$againstCond}' IN BOOLEAN MODE) >= 1 {$likeCondition})")
|
||||
->andWhere('vision')->eq($this->config->vision)
|
||||
->andWhere('objectType')->in($allowedObject)
|
||||
->andWhere('addedDate')->le(helper::now())
|
||||
->groupBy('objectType')
|
||||
->fetchPairs('objectType', 'objectCount');
|
||||
arsort($typeCount);
|
||||
return $typeCount;
|
||||
$splitedWords = $spliter->utf8Split($word);
|
||||
$trimedWord = trim($splitedWords['words']);
|
||||
$against .= '"' . $trimedWord . '" ';
|
||||
$againstCond .= '(+"' . $trimedWord . '") ';
|
||||
|
||||
if(is_numeric($word) and strpos($word, '.') === false and strlen($word) == 5) $againstCond .= "(-\" $word \") ";
|
||||
}
|
||||
|
||||
$likeCondition = '';
|
||||
/* Assisted lookup by like condition when only one word. */
|
||||
if(count($words) == 1 and strpos($words[0], ' ') === false) $likeCondition = "OR title like '%{$words[0]}%' OR content like '%{$words[0]}%'";
|
||||
|
||||
$words = str_replace('"', '', $against);
|
||||
$words = str_pad($words, 5, '_');
|
||||
|
||||
$allowedObject = array();
|
||||
|
||||
if($type != 'all')
|
||||
{
|
||||
foreach($type as $module) $allowedObject[] = $module;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->config->search->fields as $objectType => $fields)
|
||||
{
|
||||
$module = $objectType;
|
||||
if($module == 'case') $module = 'testcase';
|
||||
if(common::hasPriv($module, 'view')) $allowedObject[] = $objectType;
|
||||
|
||||
if($module == 'caselib' and common::hasPriv('caselib', 'view')) $allowedObject[] = $objectType;
|
||||
if($module == 'deploystep' and common::haspriv('deploy', 'viewstep')) $allowedobject[] = $objectType;
|
||||
}
|
||||
}
|
||||
|
||||
$scoreColumn = "(MATCH(title, content) AGAINST('{$againstCond}' IN BOOLEAN MODE))";
|
||||
|
||||
@@ -6890,8 +6890,13 @@ class upgradeModel extends model
|
||||
*/
|
||||
public function updateSearchIndex()
|
||||
{
|
||||
$this->dao->delete()->from(TABLE_SEARCHINDEX)->where('objectType')->eq('story')->exec();
|
||||
$this->loadModel('search')->buildAllIndex('story');
|
||||
$this->search->buildAllIndex('requirement');
|
||||
$requirementIds = $this->dao->select('t1.id')->from(TABLE_SEARCHINDEX)->alias('t1')
|
||||
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.objectID = t2.id')
|
||||
->where('t1.objectType')->eq('story')
|
||||
->andWhere('t2.type')->eq('requirement')
|
||||
->fetchPairs('id');
|
||||
$this->dao->update(TABLE_SEARCHINDEX)->set('objectType')->eq('requirement')->where('id')->in($requirementIds)->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user