heiheview中增加了google scholar 搜索,分离了“给我推荐”功能,整理“相关数据”“相关文献”“给我推荐”到service controller中
This commit is contained in:
parent
897b6de6a9
commit
aca061a853
|
@ -625,82 +625,6 @@ class DataController extends Zend_Controller_Action
|
|||
}
|
||||
} //viewAction
|
||||
|
||||
function relatedAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
|
||||
$sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
|
||||
left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where ";
|
||||
$where=$this->db->quoteInto('m.uuid = ?',$uuid);
|
||||
$sql.=$where;
|
||||
$row=$this->db->fetchRow($sql);
|
||||
if (!$row) exit("读取信息错误");
|
||||
$id=$row['id'];
|
||||
|
||||
//相关元数据,根据同名关键词实现
|
||||
$sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>?";
|
||||
$rows=$this->db->fetchAll($sql,array($id,$id));
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
$paginator->setView($this->view);
|
||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_related.phtml');
|
||||
$this->config = Zend_Registry::get('config');
|
||||
if ($paginator)
|
||||
{
|
||||
foreach($paginator as $c)
|
||||
{
|
||||
print '<li><a target="_blank" href="/data/'.$c['uuid'].'">'.$c['title']."</a></li>\r\n";
|
||||
}
|
||||
echo '<div class="paginator">'.$paginator.'</div>';
|
||||
}
|
||||
} //相关数据
|
||||
|
||||
function literatureAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
$sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
|
||||
left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where ";
|
||||
$where=$this->db->quoteInto('m.uuid = ?',$uuid);
|
||||
$sql.=$where;
|
||||
$row=$this->db->fetchRow($sql);
|
||||
if (!$row) exit("读取信息错误");
|
||||
$id=$row['id'];
|
||||
|
||||
$keys=$this->db->fetchAll("select * from keyword where id=? order by keytype,ts_created",array($id));
|
||||
|
||||
$wheresql = array();
|
||||
foreach ($keys as $k=>$v)
|
||||
{
|
||||
if($v['keytype']=="theme")
|
||||
$wheresql[] = " a.title like '%".$v['keyword']."%' ";
|
||||
}
|
||||
$wheresql[] = " 1<>1 ";
|
||||
$wheresql = join(" or ",$wheresql);
|
||||
$sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ($wheresql) order by a.ts_created desc";
|
||||
$rows = $this->db->fetchAll($sql);
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
$paginator->setView($this->view);
|
||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_literature.phtml');
|
||||
$this->config = Zend_Registry::get('config');
|
||||
if ($paginator)
|
||||
{
|
||||
foreach($paginator as $c)
|
||||
{
|
||||
$u=parse_url($c['url']);
|
||||
if (@$u['host']=='hdl.handle.net') $c['url'] = $this->config->seekspace->handleurl.$u['path'];
|
||||
print '<li><a target="_blank" href="'.$c['url'].'">'.$c['title'].'</a>【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】</li>";
|
||||
}
|
||||
echo '<div class="paginator">'.$paginator.'</div>';
|
||||
}
|
||||
}//相关文献
|
||||
|
||||
function replace($string){
|
||||
$patterns = array("/\"/i","/\'/i");
|
||||
$replacements = array("“","‘");
|
||||
|
|
|
@ -1008,40 +1008,142 @@ class ServiceController extends Zend_Controller_Action
|
|||
function scholar_search($keyword , $referer = 'http://westdc.westgis.ac.cn/'){
|
||||
$keyword = urlencode($keyword);
|
||||
$url = "http://scholar.google.com/scholar?q=$keyword";
|
||||
$url .= "&hl=zh-CN&btnG=搜索&lr=";
|
||||
$url .= "&hl=en&btnG=搜索&lr=";
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_REFERER, $referer);
|
||||
$body = curl_exec($ch);
|
||||
$html = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$rev = array();
|
||||
$max = 5;
|
||||
$error='';
|
||||
if(preg_match_all("#<a\sclass=\"acticle\" href=\"(.+?)\".*?>(.+?)<\/a>#im",$body,$matchs,PREG_PATTERN_ORDER))
|
||||
|
||||
if(preg_match_all("#<h3>(.+?)<\/h3>#im",$html,$matchs,PREG_PATTERN_ORDER))
|
||||
{
|
||||
foreach ($matchs[2] as $k=>$v){
|
||||
if($k < $max) $rev[$k]['title']=$v;
|
||||
}
|
||||
foreach ($matchs[1] as $k=>$v){
|
||||
if($k < $max) $rev[$k]['url']=$v;
|
||||
foreach ($matchs[0] as $k=>$v){
|
||||
if($k < $max) $rev[$k]['title']=utf8_encode($v);
|
||||
}
|
||||
}else{
|
||||
$error = "无搜索结果";
|
||||
}
|
||||
|
||||
if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)<\/span>#im",$body,$matchs,PREG_PATTERN_ORDER))
|
||||
if(preg_match_all("#<\/span>(.*)<br>(.+?)<span class=\"gs_fl\">#im",$html,$matchs,PREG_PATTERN_ORDER))
|
||||
{
|
||||
foreach ($matchs[1] as $k=>$v){
|
||||
if($k < $max) $rev[$k]['content']=$v;
|
||||
foreach ($matchs[0] as $k=>$v){
|
||||
if($k < $max) $rev[$k]['content']=utf8_encode($v);
|
||||
}
|
||||
}
|
||||
|
||||
$response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword,"error"=>$error);
|
||||
//var_dump($rev);
|
||||
//exit();
|
||||
$response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://scholar.google.com/scholar?hl=zh-CN&btnG=搜索&lr=&q='.$keyword,"error"=>$error);
|
||||
|
||||
$rev = Zend_Json::encode($response);
|
||||
return $rev;
|
||||
}//cnki 搜索
|
||||
}//scholar 搜索
|
||||
|
||||
function recommendAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
|
||||
$sql = "select d.uuid,count(distinct(d.userid)) as downtimes,m.title from dataorder d left join metadata m on d.uuid=m.uuid where d.userid in (
|
||||
select distinct(userid) from dataorder where uuid=? and status in (0,5)
|
||||
) and d.uuid<>? and length(m.title)>2 group by d.uuid,m.title order by count(distinct(d.userid)) desc";
|
||||
$rows = $this->db->fetchAll($sql,array($uuid,$uuid));
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
$paginator->setView($this->view);
|
||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_recommend.phtml');
|
||||
$this->config = Zend_Registry::get('config');
|
||||
if ($paginator)
|
||||
{
|
||||
foreach($paginator as $c)
|
||||
{
|
||||
print '<li><a target="_blank" href="/data/'.$c['uuid'].'">'.$c['title']."</a> [下载人数:".$c['downtimes']."]</li>\r\n";
|
||||
}
|
||||
echo '<div class="paginator">'.$paginator.'</div>';
|
||||
}
|
||||
}//相关下载
|
||||
|
||||
function relatedAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
|
||||
$sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
|
||||
left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where ";
|
||||
$where=$this->db->quoteInto('m.uuid = ?',$uuid);
|
||||
$sql.=$where;
|
||||
$row=$this->db->fetchRow($sql);
|
||||
if (!$row) exit("读取信息错误");
|
||||
$id=$row['id'];
|
||||
|
||||
//相关元数据,根据同名关键词实现
|
||||
$sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>?";
|
||||
$rows=$this->db->fetchAll($sql,array($id,$id));
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
$paginator->setView($this->view);
|
||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_related.phtml');
|
||||
$this->config = Zend_Registry::get('config');
|
||||
if ($paginator)
|
||||
{
|
||||
foreach($paginator as $c)
|
||||
{
|
||||
print '<li><a target="_blank" href="/data/'.$c['uuid'].'">'.$c['title']."</a></li>\r\n";
|
||||
}
|
||||
echo '<div class="paginator">'.$paginator.'</div>';
|
||||
}
|
||||
} //相关数据
|
||||
|
||||
function literatureAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
$sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid
|
||||
left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where ";
|
||||
$where=$this->db->quoteInto('m.uuid = ?',$uuid);
|
||||
$sql.=$where;
|
||||
$row=$this->db->fetchRow($sql);
|
||||
if (!$row) exit("读取信息错误");
|
||||
$id=$row['id'];
|
||||
|
||||
$keys=$this->db->fetchAll("select * from keyword where id=? order by keytype,ts_created",array($id));
|
||||
|
||||
$wheresql = array();
|
||||
foreach ($keys as $k=>$v)
|
||||
{
|
||||
if($v['keytype']=="theme")
|
||||
$wheresql[] = " a.title like '%".$v['keyword']."%' ";
|
||||
}
|
||||
$wheresql[] = " 1<>1 ";
|
||||
$wheresql = join(" or ",$wheresql);
|
||||
$sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ($wheresql) order by a.ts_created desc";
|
||||
$rows = $this->db->fetchAll($sql);
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
$paginator->setView($this->view);
|
||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_literature.phtml');
|
||||
$this->config = Zend_Registry::get('config');
|
||||
if ($paginator)
|
||||
{
|
||||
foreach($paginator as $c)
|
||||
{
|
||||
$u=parse_url($c['url']);
|
||||
if (@$u['host']=='hdl.handle.net') $c['url'] = $this->config->seekspace->handleurl.$u['path'];
|
||||
print '<li><a target="_blank" href="'.$c['url'].'">'.$c['title'].'</a>【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】</li>";
|
||||
}
|
||||
echo '<div class="paginator">'.$paginator.'</div>';
|
||||
}
|
||||
}//相关文献
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php if ($this->pageCount): ?>
|
||||
<div class="paginationControl">
|
||||
<!-- Previous page link -->
|
||||
<?php if (isset($this->previous)): ?>
|
||||
<a href="javascript:void(0);" onclick="recommend(<?php echo $this->previous;?>)">< Previous</a>
|
||||
<?php else: ?>
|
||||
<span class="disabled">< Previous</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Numbered page links -->
|
||||
<?php foreach ($this->pagesInRange as $page): ?>
|
||||
<?php if ($page != $this->current): ?>
|
||||
<a href="javascript:void(0);" onclick="recommend(<?php echo $page;?>)"><?= $page; ?></a>
|
||||
<?php else: ?>
|
||||
<span class="current"><?= $page; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<!-- Next page link -->
|
||||
<?php if (isset($this->next)): ?>
|
||||
<a href="javascript:void(0);" onclick="recommend(<?php echo $this->next;?>)">Next ></a>
|
||||
<?php else: ?>
|
||||
<span class="disabled">Next ></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
|
@ -230,11 +230,11 @@ endforeach;
|
|||
$ev = join(" ",$keywords);
|
||||
?>
|
||||
<ul class="idTabs">
|
||||
<li><a href="#related">相关数据</a></li>
|
||||
<li><a href="#literature">相关文献</a></li>
|
||||
<li><a href="#related" id="related_t">相关数据</a></li>
|
||||
<li><a href="#literature" id="literature_t">相关文献</a></li>
|
||||
<li><a href="#gsearch" class="googlesearch">相关搜索</a></li>
|
||||
<li><a href="#service">服务记录</a></li>
|
||||
<li><a href="#recommend">给我推荐</a></li>
|
||||
<li><a href="#recommend" id="recommend_t">给我推荐</a></li>
|
||||
</ul>
|
||||
<div id="related">
|
||||
</div>
|
||||
|
@ -375,14 +375,21 @@ function postcomment(){ $.ajax({'type':"POST",'url':"/data/postcomment",'data':$
|
|||
'success':function(html){$('#postcomment').html('提交');setTimeout("$('#postcomment').removeAttr('disabled');",3000); $('#returninfo').html(html);ajaxpage(0);},
|
||||
'beforeSend':function(){$('#postcomment').attr('disabled','disabled');$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...'); }});}
|
||||
|
||||
$('#literature_t').click(function(){literature(1);});
|
||||
//ajax literature
|
||||
function literature(page){$.ajax({type:"GET",url:"/data/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
|
||||
beforeSend:function(){$('#literature').html('<img src="/images/loading.gif" />加载中');}});};literature(1);
|
||||
function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
|
||||
beforeSend:function(){$('#literature').html('<img src="/images/loading.gif" />加载中');}});}
|
||||
|
||||
$('#related_t').click(function(){related(1);});
|
||||
//ajax related
|
||||
function related(page){$.ajax({type:"GET",url:"/data/related/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#related').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
|
||||
function related(page){$.ajax({type:"GET",url:"/service/related/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#related').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
|
||||
beforeSend:function(){$('#related').html('<img src="/images/loading.gif" />加载中');}});};related(1);
|
||||
|
||||
$('#recommend_t').click(function(){recommend(1);});
|
||||
//ajax recommend
|
||||
function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
|
||||
beforeSend:function(){$('#related').html('<img src="/images/loading.gif" />加载中');}});}
|
||||
|
||||
function getFileList(){
|
||||
var tw = ($(window).width() - $('#window-outter').width())/2;
|
||||
$('#window-outter').css({'right':tw});
|
||||
|
@ -440,7 +447,7 @@ function getSubFileList(uuid,id,depth){
|
|||
$('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');});
|
||||
$('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');});
|
||||
$('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');});
|
||||
$('.scholar')click(function(){});
|
||||
$('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');});
|
||||
|
||||
function googleSearch(keyword){
|
||||
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
|
||||
|
@ -465,16 +472,23 @@ function googleSearch(keyword){
|
|||
function scholarSearch(keyword){
|
||||
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
|
||||
success:function(html){
|
||||
//$('#searchlist').html(html);
|
||||
var items = [];
|
||||
var obj = jQuery.parseJSON(html);
|
||||
$.each(obj.responseData.results, function(key, val) {
|
||||
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
|
||||
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
|
||||
if(obj.error != '')
|
||||
{
|
||||
items.push('<li>' + obj.error + '</li>');
|
||||
}else{
|
||||
$.each(obj.result, function(key, val) {
|
||||
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p>'
|
||||
+'<p>'
|
||||
+val['content']
|
||||
+'</p>';
|
||||
|
||||
items.push('<li>' + html + '</li>');
|
||||
});
|
||||
items.push('<li class="more"><a href="'+obj.responseData.cursor.moreResultsUrl+'" target="_blank">查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)</a></div>');
|
||||
}
|
||||
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
|
||||
$('#searchlist').html(items.join(''));
|
||||
$('html, body').animate({scrollTop:$('html').height()}, 'slow');
|
||||
},
|
||||
|
@ -512,7 +526,7 @@ function cnkiSearch(keyword){
|
|||
items.push('<li>' + obj.error + '</li>');
|
||||
}else{
|
||||
$.each(obj.result, function(key, val) {
|
||||
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'<a/></p><p><span>'
|
||||
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p><p><span>'
|
||||
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
|
||||
+val['content']
|
||||
+'</p>';
|
||||
|
|
Loading…
Reference in New Issue