合并了我的数据中的搜索功能,利用Search类来实现多词搜索支持

This commit is contained in:
wlx 2012-03-23 07:36:32 +00:00
parent b6b9777f91
commit f43f91275f
1 changed files with 12 additions and 35 deletions

View File

@ -428,14 +428,21 @@ class AuthorController extends Zend_Controller_Action
} }
//列表 //列表
if(empty($ac) || $ac=='list'){ if(empty($ac) || $ac=='list' || $ac=='search'){
$sql = "SELECT a.*,m.title,m.description,g.id as gid FROM normalmetadata m $sql = "SELECT a.*,m.title,m.description,g.id as gid FROM normalmetadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid LEFT JOIN mdauthor a ON m.uuid=a.uuid
left join geonetworkmetadata g on m.uuid=g.uuid left join geonetworkmetadata g on m.uuid=g.uuid
WHERE a.userid=? AND status>=0 WHERE a.userid=? AND status>=0";
ORDER BY status DESC,a.id DESC if ($ac=='search')
"; {
$key = trim($this->_request->getParam('q'));
$this->view->q = $key;
$search=new Search($key);
$where=$search->sql_expr(array("m.title","m.description"));
$sql.=' and '.$where;
}
$sql.="ORDER BY status DESC,a.id DESC";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$sth->execute(array($u_id)); $sth->execute(array($u_id));
@ -450,36 +457,6 @@ class AuthorController extends Zend_Controller_Action
}//list }//list
//搜索
if($ac == "search")
{
$keyword = trim($this->_request->getParam('q'));
$this->view->q = $keyword;
if (!preg_match_all("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$keyword,$matchs))
{
$data = array('error'=>'搜索关键字中只能包含汉字、英文、数字');
}
else
{
//搜索标题和描述两个字段
$sql = "SELECT a.*,m.title,m.description FROM normalmetadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
WHERE (m.title like ? OR m.description like ?) AND a.userid=? AND status>=0
ORDER BY status DESC,a.id DESC
";
$sth = $this->db->prepare($sql);
$sth->execute(array("%$keyword%","%$keyword%",$u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(5);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
}// search
//激活数据作者 //激活数据作者
if($ac == "active") if($ac == "active")
{ {
@ -561,7 +538,7 @@ class AuthorController extends Zend_Controller_Action
}//激活数据作者 }//激活数据作者
//否认激活 //拒绝激活
if($ac == "lock") if($ac == "lock")
{ {
$this->_helper->viewRenderer('accept-active'); $this->_helper->viewRenderer('accept-active');