由于织梦DedeCMS搜索采用了分词,提升了搜索智能化,但是我们发现,搜索结果并没有变的更准确,
本篇对织梦源码搜索进行一个优化,使它的搜索结果变的更智能、准确。
首先打开/plus/search.php
找到
foreach($typeArr as $id=>$typename){$keywordn = str_replac($typename, ' ', $keyword);if($keyword != $keywordn){
改成
foreach($typeArr as $id=>$typename){//$keywordn = str_replace($typename, ' ', $keyword);$keywordn = $keyword;if($keyword != $keywordn){
然后再打开/include/arc.searchview.class.php
找到
function GetKeywords($keyword)
改成
function GetKeywords($keyword){global $cfg_soft_lang;$keyword = cn_substr($keyword, 50);$row = $this->dsql->GetOne("SELECT spwords FROM `dede_search_keywords` WHERE keyword='".addslashes($keyword)."'; ");if(!is_array($row)){if(strlen($keyword)>7){$sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);$sp->SetSource($keyword, $cfg_soft_lang, $cfg_soft_lang);$sp->SetResultType(2);$sp->StartAnalysis(TRUE);$keywords = $sp->GetFinallyResult();$idx_keywords = $sp->GetFinallyIndex();ksort($idx_keywords);$keywords = $keyword.' ';foreach ($idx_keywords as $key => $value) {if (strlen($key) <= 3) {continue;}$keywords .= ' '.$key;}$keywords = preg_replace("/[ ]{1,}/", " ", $keywords);//var_dump($idx_keywords);exit();unset($sp);}else{$keywords = $keyword;}$inquery = "INSERT INTO `dede_search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`)VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); ";$this->dsql->ExecuteNoneQuery($inquery);}else{$this->dsql->ExecuteNoneQuery("UPDATE `dede_search_keywords` SET count=count+1,lasttime='".time()."' WHERE keyword='".addslashes($keyword)."'; ");$keywords = $row['spwords'];}return $keywords;}