diff --git a/module/search/control.php b/module/search/control.php index 44017bd6b9..2cdee4a507 100644 --- a/module/search/control.php +++ b/module/search/control.php @@ -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) { diff --git a/module/search/lang/de.php b/module/search/lang/de.php index 4e402047dd..3e713b45db 100644 --- a/module/search/lang/de.php +++ b/module/search/lang/de.php @@ -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; diff --git a/module/search/lang/en.php b/module/search/lang/en.php index f7ad62e571..cb96084ad9 100644 --- a/module/search/lang/en.php +++ b/module/search/lang/en.php @@ -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; diff --git a/module/search/lang/fr.php b/module/search/lang/fr.php index f03bed6c52..dfec24804c 100644 --- a/module/search/lang/fr.php +++ b/module/search/lang/fr.php @@ -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; diff --git a/module/search/lang/zh-cn.php b/module/search/lang/zh-cn.php index 5a0a3c6547..fb6ffe0968 100644 --- a/module/search/lang/zh-cn.php +++ b/module/search/lang/zh-cn.php @@ -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; diff --git a/module/search/model.php b/module/search/model.php index bb57990d84..6645051ed6 100644 --- a/module/search/model.php +++ b/module/search/model.php @@ -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))"; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index f3662c27d4..7c9813c655 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -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(); } }